<template>
  <div class="EmergencyList">
    <div class="flex location-wrap">
      <span class="white">当前位置：</span>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/EDManagement' }">应急处置</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/ResourceAllocation' }">资源调配</el-breadcrumb-item>
        <el-breadcrumb-item>{{ this.applyType == 1 ? "队伍" : this.applyType == 2 ? "车辆" : this.applyType == 3 ? "装备" :
          "物资" }}派遣</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="box">
      <!-- 列表筛选 -->
      <filterTitle @query="onSubmit(form)" @reset="resetForm" :form="form" @node-click="handleSelectTree"
        :formData="formData" labelWidth="140px">
        <!-- <el-form slot="filter" class="form" ref="form" :model="form" inline size="small" label-width="140px">
          <el-form-item :label="item.label+'：'" v-for="(item, index) in formData" :key="index" :prop="item.id">
            <LsdForm :compData="item" />
          </el-form-item>
        </el-form> -->
      </filterTitle>
      <!-- 列表表格 -->
      <LsdTable slot="pqlist" ref="pqlist" @pageChange="handleSizeChange($event,form)" :paginationAtrrs="table.paginationAtrrs"
        :compRef="table.compRef" :columns="table.columns" :title="table.title" :actions="table.actions"
        :tableData="table.tableData" :tableAttr="table.tableAttr" :isShowPage="table.isShowPage"
        :isSequenceFlag="table.isSequenceFlag" @onActionClick="tableClick" />
    </div>
    <!-- 弹窗信息 -->
    <LsdDialog :dialogConfig="dispatchDialog.dialogConfig" @handleBtn="formClick" @close="cancel"
      v-if="dispatchDialog.dialogConfig.isShow">
      <LsdDialogTitle slot="dialog" :titleConfig="dispatchDialog.titleConfig" :activeNames="activeNames"
        @getResourcesData="getResourcesData" :btnShow="btnShow">
        <DialogForm ref="formComponent1" slot="slot1" :formConfig="dispatchDialog.formConfig1" />
        <!-- 新增派遣时任务信息 slot8-->
        <DialogForm ref="formComponent8" slot="slot8" :formConfig="dispatchDialog.formConfig8"
          @handleNodeClick="changeEvent8" @changeEvent="changeLxr" />
        <DialogForm ref="formComponent2" slot="slot2" :formConfig="dispatchDialog.formConfig2" />
        <div slot="slot3" class="tableDiv">
          <LsdTable :compRef="dispatchDialog.formConfig3.table.compRef"
            :autoHeight="dispatchDialog.formConfig3.table.autoHeight" :columns="dispatchDialog.formConfig3.table.columns"
            :tableData="dispatchDialog.formConfig3.table.tableData"
            :tableAttr="dispatchDialog.formConfig3.table.tableAttr"
            :isSequenceFlag="dispatchDialog.formConfig3.table.isSequenceFlag" />
        </div>
        <div slot="slot4" v-show="auth[0]" class="tableDiv">
          <DialogForm ref="formComponent4" :formConfig="dispatchDialog.formConfig4" :name="dispatchDialog.name"
            @handleNodeClick="changeEvent4" />
          <div v-if="applyType === 1">
            <!-- 判断是否存在下发,存在就不显示上级的teamTableList -->
            <div v-if="auth[0] && !auth[1]">
              <div class="marginB5" v-for="(item, index) in teamTableList" :key="index">
                <DialogForm :ref="`formComponent4${index}`" :formConfig="dispatchDialog.formConfig4.teamListConfig"
                  :name="dispatchDialog.name" />
                <LsdTable v-if="item.memberSaveDtoList.length > 0"
                  :autoHeight="dispatchDialog.formConfig4.teamListConfig.table.autoHeight"
                  :columns="dispatchDialog.formConfig4.teamListConfig.table.columns" :tableData="item.memberSaveDtoList"
                  :tableAttr="dispatchDialog.formConfig4.teamListConfig.table.tableAttr"
                  :isSequenceFlag="dispatchDialog.formConfig4.teamListConfig.table.isSequenceFlag" />
              </div>
            </div>
          </div>
          <div v-else>
            <LsdTable v-if="dispatchDialog.formConfig4.table.tableData.length > 0"
              :autoHeight="dispatchDialog.formConfig4.table.autoHeight"
              :compRef="dispatchDialog.formConfig4.table.compRef" :columns="dispatchDialog.formConfig4.table.columns"
              :tableData="dispatchDialog.formConfig4.table.tableData"
              :tableAttr="dispatchDialog.formConfig4.table.tableAttr"
              :isSequenceFlag="dispatchDialog.formConfig4.table.isSequenceFlag" />
          </div>
        </div>
        <div slot="slot5" v-show="auth[1]" class="tableDiv">
          <DialogForm ref="formComponent5" :formConfig="dispatchDialog.formConfig5" :name="dispatchDialog.name"
            @handleNodeClick="changeEvent5" />
          <div v-if="applyType === 1">
            <!-- 判断是否存在下发,存在就不显示上级的teamTableList -->
            <div v-if="auth[1] && !auth[2]">
              <div class="marginB5" v-for="(item, index) in teamTableList" :key="index">
                <DialogForm :ref="`formComponent5${index}`" :formConfig="dispatchDialog.formConfig5.teamListConfig"
                  :name="dispatchDialog.name" />
                <LsdTable v-if="item.memberSaveDtoList.length > 0"
                  :autoHeight="dispatchDialog.formConfig5.teamListConfig.table.autoHeight"
                  :columns="dispatchDialog.formConfig5.teamListConfig.table.columns" :tableData="item.memberSaveDtoList"
                  :tableAttr="dispatchDialog.formConfig5.teamListConfig.table.tableAttr"
                  :isSequenceFlag="dispatchDialog.formConfig5.teamListConfig.table.isSequenceFlag" />
              </div>
            </div>
          </div>
          <div v-else>
            <LsdTable v-if="dispatchDialog.formConfig5.table.tableData.length > 0"
              :autoHeight="dispatchDialog.formConfig5.table.autoHeight"
              :compRef="dispatchDialog.formConfig5.table.compRef" :columns="dispatchDialog.formConfig5.table.columns"
              :tableData="dispatchDialog.formConfig5.table.tableData"
              :tableAttr="dispatchDialog.formConfig5.table.tableAttr"
              :isSequenceFlag="dispatchDialog.formConfig5.table.isSequenceFlag" />
          </div>
        </div>
        <div slot="slot6" v-show="auth[2]" class="tableDiv">
          <DialogForm ref="formComponent6" :formConfig="dispatchDialog.formConfig6" :name="dispatchDialog.name"
            @handleNodeClick="changeEvent6" />
          <div v-if="applyType === 1">
            <div class="marginB5" v-for="(item, index) in teamTableList" :key="index">
              <DialogForm :ref="`formComponent6${index}`" :formConfig="dispatchDialog.formConfig6.teamListConfig"
                :name="dispatchDialog.name" />
              <LsdTable v-if="item.memberSaveDtoList.length > 0"
                :autoHeight="dispatchDialog.formConfig6.teamListConfig.table.autoHeight"
                :columns="dispatchDialog.formConfig6.teamListConfig.table.columns" :tableData="item.memberSaveDtoList"
                :tableAttr="dispatchDialog.formConfig6.teamListConfig.table.tableAttr"
                :isSequenceFlag="dispatchDialog.formConfig6.teamListConfig.table.isSequenceFlag" />
            </div>
          </div>
          <div v-else>
            <LsdTable v-if="dispatchDialog.formConfig6.table.tableData.length > 0"
              :autoHeight="dispatchDialog.formConfig6.table.autoHeight"
              :compRef="dispatchDialog.formConfig6.table.compRef" :columns="dispatchDialog.formConfig6.table.columns"
              :tableData="dispatchDialog.formConfig6.table.tableData"
              :tableAttr="dispatchDialog.formConfig6.table.tableAttr"
              :isSequenceFlag="dispatchDialog.formConfig6.table.isSequenceFlag" />
          </div>
        </div>
        <DialogForm ref="formComponent7" slot="slot7" :formConfig="dispatchDialog.formConfig7" />
      </LsdDialogTitle>
    </LsdDialog>
    <!-- 选择弹窗信息 -->
    <DialogChoose ref="ChooseConfig" :ChooseConfig="ChooseConfig" @teamAdd="teamAdd" @handleChooseChange="dialogQuery"
      @query="dialogQuery" @reset="dialogReset" @close="chooseClose" :ChooseFormConfig="ChooseFormConfig"
      :ChooseTableConfig="ChooseTableConfig" v-if="ChooseConfig.isShow"></DialogChoose>
  </div>
</template>

<script>
import { cloneDeep } from "lodash";
import { showTime } from "@/lib";
import { TeamDataConfig1, TeamDataConfig2, CarDataConfig1, CarDataConfig2, EquipmentDataConfig0, EquipmentDataConfig1, EquipmentDataConfig2, MaterialDataConfig0, MaterialDataConfig1, MaterialDataConfig2 } from "./ChooseDialog.js";
import { TeamFormDialog, CarFormDialog, EquipmentFormDialog, MaterialFormDialog } from "./DispatchDialog.js";
import { TeamList, CarList, EquipmentList, MaterialList } from "./ResourceList";
// eslint-disable-next-line no-unused-vars
import { GetDispacthList, GetDispacthDetail, GetTeamResource, GetTeamMemberResource, GetResourceWarehouse, GetVehicleResource, GetEquipResource, GetSuppliesResource, GetDemandLevel, getWarehouseName, SendDispacthList, DispacthApprove, DispacthDeleted } from "@/api/EmergencyDisposal/zydp.js";
import { GetSystemUsers, GetResponse, GetByOrganization, getBatchDicList, getUnitAndNextUnit, getDepartmentNext, getAccountOrgById } from "@/api/common.js";
import { flowSubmit } from "@/utils/flow";
export default {
  name: "ResourceDispatchList",
  components: {},
  data() {
    return {
      teamTableList: [
      ],
      teamIndex: 0,
      teamTableLength: 0,
      resourceFathersId: "",
      dispatchedStatus: 999, // 999是新增
      orderType: "", // 派遣单apply 申请过来的派遣单, dispatched 新增的派遣单
      applyLevel: 0, // 申请单位级别 省：1，市：2，县：3
      acceptLevel: 0, // 受理单位级别 省：1，市：2，县：3
      isSend: false, // 是否下发过
      Userorg: JSON.parse(sessionStorage.getItem("org")), // 当前登录人部门级别
      roleCode: JSON.parse(sessionStorage.getItem("role")).roleCode, // 当前登录人id
      UserInfo: {
        userName: JSON.parse(sessionStorage.getItem("account")) && JSON.parse(sessionStorage.getItem("account")).realName || ""
      },
      dwbmName: sessionStorage.getItem("dwbmName"),
      TeamDataConfig1: TeamDataConfig1, // 队伍
      TeamDataConfig2: TeamDataConfig2, // 队员
      CarDataConfig1: CarDataConfig1, // 车辆台账
      CarDataConfig2: CarDataConfig2, // 车辆
      EquipmentDataConfig0: EquipmentDataConfig0, // 装备台账
      EquipmentDataConfig1: EquipmentDataConfig1, // 装备仓库
      EquipmentDataConfig2: EquipmentDataConfig2, // 装备
      MaterialDataConfig0: MaterialDataConfig0, // 物资台账
      MaterialDataConfig1: MaterialDataConfig1, // 物资仓库
      MaterialDataConfig2: MaterialDataConfig2, // 物资
      form: {
        sourceInfo: "", // 响应命令单
        resourceDispatchedName: "", // 资源派遣单
        dutyUnit: "", // 责任单位及部门
        dutyUnitId: "", // 责任单位及部门
        dutyPersonId: "", // 责任人
        dispatchedStartTime: "", // 开始时间
        dispatchedEndTime: "" // 结束时间
      },
      // 列表筛选信息
      formData: [
        {
          elType: "input",
          id: "sourceInfo",
          label: "响应命令单",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            "collapse-tags": true
          }
        },
        {
          elType: "input",
          id: "resourceDispatchedName",
          label: "资源派遣单",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            "collapse-tags": true
          }
        },
        {
          elType: "selectTree",
          id: "dutyUnit",
          name: "dutyUnitId",
          label: "责任单位及部门",
          attrs: {
            value: "",
            clearable: true,
            "collapse-tags": true
          },
          options: {
            attrs: {
              value: ""
            }
          },
          treeData: {
            attrs: {
              data: []
            },
            props: {
              children: "children",
              label: "orgName",
              value: "id"
            }
          }
        },
        {
          elType: "select",
          id: "dutyPersonId",
          label: "责任人",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "dateTimePicker",
          id: "dispatchedTime",
          label: "派遣时间",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            type: "datetimerange",
            "value-format": "yyyy-MM-dd HH:mm:ss"
          }
        },
        {
          elType: "select",
          id: "dispatchedStatus",
          label: "状态",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            "collapse-tags": true
          },
          options: [
            {
              label: "编辑中",
              value: "1"
            },
            {
              label: "待派遣",
              value: "2"
            },
            {
              label: "待审批",
              value: "3"
            },
            {
              label: "已审批",
              value: "4"
            },
            {
              label: "已接收",
              value: "5"
            },
            {
              label: "驳回",
              value: "6"
            }
          ]
        }
      ],
      table: {},
      total: 0,
      pageNum: 1, // 列表
      pageSize: 10,
      // 派遣表单
      dispatchDialog: {
        dialogConfig: {
          title: "队伍派遣单",
          isShow: false,
          btnList: [
            {
              name: "下发",
              type: "primary",
              id: "submit",
              size: "small"
            },
            {
              name: "取消",
              id: "cancel",
              size: "small"
            }
          ]
        }
      },
      activeNames: ["1", "2", "3", "4", "5", "6", "7", "8"],
      // 队伍、队员选择弹窗信息
      ChooseConfig: {
        title: "",
        isShow: false
      },
      // 查询条件
      ChooseFormConfig: {
        formData: []
      },
      // 数据
      ChooseTableConfig: {
      },
      applyType: 1, // 资源类型
      dispatchId: "", // 派遣单ID
      Usersoptions: "", // 部门下的人员信息
      btnShow: true
    };
  },
  watch: {
    // 侦听路由器参数变化
    $route: {
      handler(newVal, oldval) {
        if (newVal.query.type !== oldval.query.type) {
          this.switchRoute();
        }
      }
    }
  },
  computed: {
    auth() {
      // 派遣单类型orderType:  apply 申请过来的派遣单, dispatched 新增的派遣单
      // 派遣单状态dispatchedStatus:  1-编辑中，2-待派遣，3-待审批，4-已审批 5-已接收 6-驳回
      const auth = [false, false, false];
      if ([1, 3, 6, 999].includes(this.dispatchedStatus)) {
        // 点击新增、编辑、审批
        if (this.Userorg.level === 1) {
          auth[0] = true;
        } else if (this.Userorg.level === 2) {
          auth[1] = true;
        } else {
          auth[2] = true;
        }
      } else if (this.dispatchedStatus == 2) { // 待派遣
        if (this.acceptLevel === 1) { // 省
          if (this.applyLevel === 2 && this.isSend) { // 存在下发
            auth[0] = true;
            auth[1] = true;
          } else {
            auth[0] = true;
          }
        } else if (this.acceptLevel === 2) { // 市
          if (this.applyLevel === 3 && this.isSend) { // 存在下发
            auth[1] = true;
            auth[2] = true;
          } else {
            auth[1] = true;
          }
        }
      }
      //  else if (this.dispatchedStatus == 3) { // 待审批
      //   if (this.orderType === "apply") { // 申请过来的派遣单
      //     if (this.acceptLevel === 1) { // 受理级别 省
      //       if (this.applyLevel === 2) { // 申请级别
      //         if (this.isSend) { // 有无下发
      //           auth[0] = true;
      //           auth[1] = true;
      //         } else {
      //           auth[0] = true;
      //         }
      //       }
      //     } else if (this.acceptLevel === 2) { // 受理级别 市
      //       if (this.applyLevel === 3) { // 申请级别
      //         if (this.isSend) { // 有无下发
      //           auth[1] = true;
      //           auth[2] = true;
      //         } else {
      //           auth[1] = true;
      //         }
      //       }
      //     }
      //   } else {
      //     if (this.Userorg.level === 1) {
      //       auth[0] = true;
      //     } else if (this.Userorg.level === 2) {
      //       auth[1] = true;
      //     } else {
      //       auth[2] = true;
      //     }
      //   }

      // }
      return auth;
    }
  },
  mounted() {
    this.switchRoute();
  },
  methods: {
    switchRoute() {
      if (this.$route.query.type === "team") {
        this.applyType = 1;
        this.table = TeamList(this).table;
        this.dispatchDialog = cloneDeep(TeamFormDialog);
      } else if (this.$route.query.type === "car") {
        this.applyType = 2;
        this.table = CarList(this).table;
        this.dispatchDialog = cloneDeep(CarFormDialog);
      } else if (this.$route.query.type === "equipment") {
        this.applyType = 3;
        this.table = EquipmentList(this).table;
        this.dispatchDialog = cloneDeep(EquipmentFormDialog);
      } else if (this.$route.query.type === "material") {
        this.applyType = 4;
        this.table = MaterialList(this).table;
        this.dispatchDialog = cloneDeep(MaterialFormDialog);
      }
      // 省级新增按钮
      // if (this.Userorg.level === 2) {
      //   this.table.actions = [];
      // }
      this.resetForm();
      this.GetDispacthLists();
      this.getInputVal();
    },
    // 获取列表信息
    async GetDispacthLists() {
      const parmas = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        applyType: this.applyType
      };
      const res = await GetDispacthList(parmas);
      this.table.tableData = res.data;
      this.table.paginationAtrrs.total = res.total;
    },
    getGetResponse() {
      GetResponse({ orgId: this.Userorg.orgId }).then(res => { // 响应命令单
        // 表单选项是option , 筛选条件选项是options
        const option = res.map((item) => {
          return {
            label: item.responseName,
            value: item.id
          };
        });
        this.dispatchDialog.formConfig1.formData[0].option = option;
      });
    },
    // 获取下拉框数据
    getInputVal() {
      this.getGetResponse();
      this.formData.forEach((item) => {
        if (item.name === "dutyUnitId") {
          getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
            item.treeData.attrs.data = res;
          });
        }
        if (item.id === "dutyPersonId") { // 责任人
          GetSystemUsers().then(res => {
            const option = res.map((val) => {
              return {
                label: val.realName,
                value: val.id
              };
            });
            item.options = option;
          });
        }
      });
      // this.dispatchDialog.formConfig2.formData.forEach((item) => {
      //   if (item.prop === "contact") { // 联系人
      //     GetSystemUsers().then(res => {
      //       const option = res.map((val) => {
      //         return {
      //           label: val.realName,
      //           value: val.id
      //         };
      //       });
      //       item.option = option;
      //     });
      //   }
      //   if (item.prop === "applyEvel") { // 需求等级
      //     GetDemandLevel().then(res => {
      //       const option = res.map((val) => {
      //         return {
      //           label: val.name,
      //           value: Number(val.code)
      //         };
      //       });
      //       item.option = option;
      //     });
      //   }
      //   if (item.prop === "acceptUnitId" || item.prop === "applyUnitId") {
      //     GetOrgTree().then(res => {
      //       const option = res.map((val) => {
      //         return {
      //           label: val.orgName,
      //           value: val.id
      //         };
      //       });
      //       item.option = option;
      //     });
      //   }
      // });
      this.dispatchDialog.formConfig8.formData.forEach((item) => {
        if (item.prop === "acceptUnit") {
          getUnitAndNextUnit({ orgId: this.Userorg.orgId }).then(res => {
            item.treeData.data = res;
          });
        }
      });
    },
    tableClick(item, index) {
      this[item.id](); // 调用列表table按钮对应方法
    },
    // 新增的任务信息表单请求
    changeEvent8(item, nowId, index) {
      console.log(item, nowId, index, "item, nowId, index");
      if (item.label == "接收单位") {
        if (nowId) {
          GetByOrganization({ orgId: nowId }).then(res => {
            this.Usersoptions = res;
            const option = res.map((i) => {
              return {
                label: i.realName,
                value: i.userId
              };
            });
            this.dispatchDialog.formConfig8.formData[index + 1].option = option;
          });
        }
      }
    },
    changeLxr(val, item) {
      console.log(val, item);
      if (item.label === "联系人") {
        let obj = {};
        obj = this.Usersoptions.find((s) => {
          return s.userId == val; // 筛选出匹配数据选的和返回他的电话
        });
        this.$set(this.$refs.formComponent8.form, "contactWay", obj.phone);
      }
    },
    // 省公司选择地市级部门带出负责人
    changeEvent4(item, nowId) {
      if (item.label == "责任单位及部门") {
        if (nowId) {
          getAccountOrgById({ ssbmId: nowId }).then(res => {
            const option = res.map((i) => {
              return {
                label: i.realName,
                value: i.id
              };
            });
            this.dispatchDialog.formConfig4.formData[2].option = option;
          });
        }
      }
    },
    // 地市级选择区县部门带出负责人
    changeEvent5(item, nowId, index) {
      if (item.label == "责任单位及部门") {
        if (nowId) {
          getAccountOrgById({ ssbmId: nowId }).then(res => {
            const option = res.map((i) => {
              return {
                label: i.realName,
                value: i.id
              };
            });
            this.dispatchDialog.formConfig5.formData[index + 1].option = option;
          });
        }
      }
    },
    // 区县级选择区县部门带出负责人
    changeEvent6(item, nowId, index) { // index 是 修改表单item项的位置后找到对应元素
      if (item.label == "责任单位及部门") {
        if (nowId) {
          getAccountOrgById({ ssbmId: nowId }).then(res => {
            const option = res.map((i) => {
              return {
                label: i.realName,
                value: i.id
              };
            });
            this.dispatchDialog.formConfig6.formData[index + 1].option = option;
          });
        }
      }
    },
    // 调用表单按钮对应方法
    formClick(item) {
      this[item.id](item);
    },
    // 表单提交判断接口url
    submit(item) {
      let url = "";
      if (item.name === "提交") { // 提交
        url = "submit";
      } else if (item.name === "下发") { // 下发
        url = "send";
      } else if (item.name === "保存") { // 保存
        url = "save";
      }
      this.SendDispacthLists(url);
    },
    // 表单提交
    async SendDispacthLists(url) {
      const { level } = this.Userorg;
      let flag = "";
      let form = {};
      // eslint-disable-next-line no-unused-vars
      let tableDatas = [];
      if (this.addOredit === 0) { // 新增时 校验任务信息表单
        this.$refs.formComponent8.isValidate();
        flag = this.$refs.formComponent8.flag;
      }
      if (level === 1) { // 根据部门校验对应表单
        this.$refs.formComponent4.isValidate();
        flag = this.$refs.formComponent4.flag;
        form = this.$refs.formComponent4.form;
        if (this.applyType === 1) {
          tableDatas = this.teamTableList;
        } else {
          tableDatas = this.dispatchDialog.formConfig4.table.tableData;
        }
      } else if (level === 2) { // 根据部门校验对应表单
        this.$refs.formComponent5.isValidate();
        flag = this.$refs.formComponent5.flag;
        form = this.$refs.formComponent5.form;
        if (this.applyType === 1) {
          tableDatas = this.teamTableList;
        } else {
          tableDatas = this.dispatchDialog.formConfig5.table.tableData;
        }
      } else if (level >= 3) { // 根据部门校验对应表单
        this.$refs.formComponent6.isValidate();
        flag = this.$refs.formComponent6.flag;
        form = this.$refs.formComponent6.form;
        if (this.applyType === 1) {
          tableDatas = this.teamTableList;
        } else {
          tableDatas = this.dispatchDialog.formConfig6.table.tableData;
        }
      }
      if (url === "submit") {
        if (tableDatas.length == 0) {
          flag = false;
          this.$message({
            message: "请选择对应资源",
            type: "success"
          });
        }
      }
      if (flag) {

        const dispatchedSaveDtoList = [];
        const datas = {
          id: form.id || "",
          resourceDispatchedName: form.resourceDispatchedName,
          dutyUnit: form.dutyUnit,
          dutyUnitId: typeof (form.dutyUnitId) === "object" ? form.dutyUnitId[form.dutyUnitId.length - 1] : form.dutyUnitId || "",
          dutyPersonId: form.dutyPersonId || "",
          dutyPerson: form.dutyPerson || "",
          dispatchedLevel: level,
          // teamName: form.teamName || "",
          // teamType: form.teamType || "",
          // teamMajor: form.teamMajor || "",
          warehouseName: form.warehouseName || "",
          warehouseContact: form.warehouseContact || "",
          warehouseContactWay: form.warehouseContactWay || "",
          dispatchedNum: form.dispatchedNum || ""
        };
        if (this.applyType === 1) {
          datas.teamSaveDtoList = tableDatas || [];
        } else if (this.applyType === 2) {
          datas.vehicleSaveDtoList = tableDatas || [];
        } else if (this.applyType === 3) {
          datas.equipDetailDtoList = tableDatas || [];
        } else if (this.applyType === 4) {
          datas.suppliesDetailDtoList = tableDatas || [];
        }
        dispatchedSaveDtoList.push(datas); // 派遣的信息
        const parmas = {
          dispatchedSaveDtoList: dispatchedSaveDtoList
        };
        if (this.addOredit === 0) { // 新增
          // 新增时的任务信息表单 applySaveDto object
          const datas = this.$refs.formComponent8.form.acceptUnitId;
          this.$set(this.$refs.formComponent8.form, "acceptUnitId", datas);
          parmas.applySaveDto = Object.assign(this.$refs.formComponent1.form, this.$refs.formComponent8.form);
          parmas.applySaveDto.applyType = this.applyType; // 新增时传入资源类型
          if (url === "submit") {
            const res = await SendDispacthList(parmas, "save");
            if (res) {
              this.gzlSubmit(res, parmas); // 1是新增
            }
            console.log("object2");
          } else {
            const res = await SendDispacthList(parmas, url);
            if (res) {
              this.$message({
                message: "保存成功",
                type: "success"
              });
            }
          }
        } else if (this.addOredit === 1) { // 派遣，编辑
          parmas.applyIdOrDispatchedId = this.dispatchId;
          if (this.orderType === "dispatched") {
            const datas = this.$refs.formComponent8.form.acceptUnitId;
            this.$set(this.$refs.formComponent8.form, "acceptUnitId", datas);
            parmas.applySaveDto = Object.assign(this.$refs.formComponent1.form, this.$refs.formComponent8.form);
            parmas.applySaveDto.applyType = this.applyType; // 新增时传入资源类型
            console.log("编辑", parmas);
          }
          if (url === "save") { // 更新
            const res = await SendDispacthList(parmas, "updById");
            if (res) {
              this.$message({
                message: "保存成功",
                type: "success"
              });
            }
          } else if (url === "send") {
            // this.gzlSubmit(this.dispatchId, parmas, 2);
            const res = await SendDispacthList(parmas, url);
            if (res) {
              this.$message({
                message: "操作成功",
                type: "success"
              });
            }
          } else if (url === "submit") {
            if (this.orderType === "apply") { // 申请派遣提交
              const res = await SendDispacthList(parmas, url);
              if (res) {
                this.$message({
                  message: "操作成功",
                  type: "success"
                });
              }
            } else { // 新增保存后提交
              console.log(parmas, "新增保存后提交");
              this.gzlSubmit(this.dispatchId, parmas);
            }
          }
        }
        this.cancel();
        this.GetDispacthLists();
      }
    },

    // 工作流提交
    gzlSubmit(bizKey, variable) {
      const taskId = "task1";
      const idea = "1";
      const flowKey = "team_direct_001";
      const callbackUrl = "/emergency/emergencyResourceAllocation/handleFlowNotice";
      //  type 1新增提交，2下发，3派遣提交
      // if (type === 1) {
      //   taskId = "task1";
      //   flowKey = "team_direct_001";
      //   callbackUrl = "/emergency/emergencyResourceAllocation/handleFlowNotice";
      // } else if (type === 2) {
      //   idea = "0";
      //   taskId = "task3";
      // } else if (type === 3) {
      //   taskId = "task3";
      // } else if (type === 4) {
      //   idea = "1";
      //   taskId = "task4";
      // }
      const data = {
        bizKey,
        flowKey: flowKey,
        taskId: taskId,
        callbackUrl: callbackUrl,
        idea: idea,
        variable
      };
      const successCallBack = () => {
        this.$message({
          message: "操作成功",
          type: "success"
        });
        this.GetDispacthLists();
      };
      flowSubmit(data, successCallBack, "提交", true);
    },

    // 工作流审批
    gzlAudit(type, variable) {
      const data = {
        bizKey: this.dispatchId,
        flowKey: this.orderType === "dispatched" ? "team_direct_001" : "team_resource_002",
        taskId: this.orderType === "dispatched" ? "task2" : this.isSend ? "task5" : "task6", // 先判断派遣单类型，再判断 是否存在下发
        callbackUrl: this.orderType === "dispatched" ? "/emergency/emergencyResourceAllocation/handleFlowNotice" : "/emergency/emergencyResourceAllocation/handleFlow",
        idea: type === 3 ? "1" : "0",
        variable,
        ideaMsg: this.$refs.formComponent7.form.dispatchedApprovalOpinion ? this.$refs.formComponent7.form.dispatchedApprovalOpinion : type === 3 ? "同意" : "驳回"
      };
      const successCallBack = () => {
        this.$message({
          message: `${type === 3 ? "审核" : "驳回"}成功`,
          type: "success"
        });
        this.GetDispacthLists();
      };
      flowSubmit(data, successCallBack, "审核");
    },

    // 关闭弹窗
    cancel() {
      this.btnShow = true; // 重置台账、仓库3个按钮显示
      this.dispatchDialog.dialogConfig.isShow = false;
      const { formComponent4, formComponent5, formComponent6 } = this.$refs;
      formComponent4?.form?.$refs?.formInlines?.resetFields();
      formComponent5?.form?.$refs?.formInlines?.resetFields();
      formComponent6?.form?.$refs?.formInlines?.resetFields();
      // if (this.Userorg.level === 1) { // 省公司
      //   this.$refs.formComponent4.form = this.$refs.formComponent4.$options.data().form
      //   this.dispatchDialog.formConfig4.table.tableData = []
      // } else if (this.Userorg.level === 2) { // 地市
      //   this.$refs.formComponent5.form = this.$refs.formComponent5.$options.data().form
      //   this.dispatchDialog.formConfig5.table.tableData = []
      // } else if (this.Userorg.level >= 3) { // 区县
      //   this.$refs.formComponent6.form = this.$refs.formComponent6.$options.data().form
      //   this.dispatchDialog.formConfig6.table.tableData = []
      // }
      if (this.$route.query.type === "team") {
        this.dispatchDialog = cloneDeep(TeamFormDialog);
      } else if (this.$route.query.type === "car") {
        this.dispatchDialog = cloneDeep(CarFormDialog);
      } else if (this.$route.query.type === "equipment") {
        this.dispatchDialog = cloneDeep(EquipmentFormDialog);
      } else if (this.$route.query.type === "material") {
        this.dispatchDialog = cloneDeep(MaterialFormDialog);
      }
      this.teamTableList = [];
    },
    // 根据不同操作获取派遣详情
    async GetDispacthDetails(id, type) {
      this.dispatchDialog.dialogConfig.isShow = true;
      const res = await GetDispacthDetail({ id });
      const { applyDetailVo, dispatchedDetailVoList } = res;
      this.$refs.formComponent1.form = applyDetailVo;
      this.dispatchedStatus = applyDetailVo.dispatchedStatus; // 派遣单状态dispatchedStatus
      this.orderType = applyDetailVo.orderType; // 派遣单类型orderType
      this.applyLevel = applyDetailVo.applyLevel; // 申请单位级别 省：1，市：2，县：3
      this.acceptLevel = applyDetailVo.acceptLevel; // 受理单位级别 省：1，市：2，县：3
      this.isSend = dispatchedDetailVoList.length > 0 ? dispatchedDetailVoList[0].isSend : false; // 是否下发过
      // 派遣、申请派遣单当前登录人赋值
      if (type === "dispatch") { // 点派遣的时候
        this.dispatchDialog.formConfig1.rules = {};
        if (this.acceptLevel === 1) {
          if (this.applyLevel === 2 && this.isSend) {
            this.dispatchDialog.dialogConfig.btnList = [
              {
                name: "提交",
                type: "primary",
                id: "submit",
                size: "small"
              },
              {
                name: "保存",
                id: "submit",
                size: "small"
              },
              {
                name: "取消",
                id: "cancel",
                size: "small"
              }
            ];
            this.dispatchDialog.formConfig4.formData.forEach((item) => { item.isDisabled = true; });
            this.dispatchDialog.formConfig4.rules = {};
            this.$set(this.$refs.formComponent5.form, "creator", this.UserInfo.userName);
            this.$set(this.$refs.formComponent5.form, "creatorUnit", this.dwbmName);
            this.$set(this.$refs.formComponent5.form, "createTime", showTime(new Date()));
          } else {
            this.$set(this.$refs.formComponent4.form, "creator", this.UserInfo.userName);
            this.$set(this.$refs.formComponent4.form, "creatorUnit", this.dwbmName);
            this.$set(this.$refs.formComponent4.form, "createTime", showTime(new Date()));
          }
        } else if (this.acceptLevel === 2) {
          if (this.applyLevel === 3 && this.isSend) {
            this.dispatchDialog.dialogConfig.btnList = [
              {
                name: "提交",
                type: "primary",
                id: "submit",
                size: "small"
              },
              {
                name: "保存",
                id: "submit",
                size: "small"
              },
              {
                name: "取消",
                id: "cancel",
                size: "small"
              }
            ];
            this.dispatchDialog.formConfig4.formData.forEach((item) => { item.isDisabled = true; });
            this.dispatchDialog.formConfig4.rules = {};
            this.$set(this.$refs.formComponent5.form, "creator", this.UserInfo.userName);
            this.$set(this.$refs.formComponent5.form, "creatorUnit", this.dwbmName);
            this.$set(this.$refs.formComponent5.form, "createTime", showTime(new Date()));
          } else {

            this.$set(this.$refs.formComponent4.form, "creator", this.UserInfo.userName);
            this.$set(this.$refs.formComponent4.form, "creatorUnit", this.dwbmName);
            this.$set(this.$refs.formComponent4.form, "createTime", showTime(new Date()));
          }
        }
        // } else if (this.acceptLevel === 3) {
        //   this.dispatchDialog.dialogConfig.btnList = [
        //     {
        //       name: "提交",
        //       type: "primary",
        //       id: "submit",
        //       size: "small"
        //     },
        //     {
        //       name: "保存",
        //       id: "submit",
        //       size: "small"
        //     },
        //     {
        //       name: "取消",
        //       id: "cancel",
        //       size: "small"
        //     }
        //   ];
        //   this.$set(this.$refs.formComponent4.form, "creator", this.UserInfo.userName);
        //   this.$set(this.$refs.formComponent4.form, "creatorUnit", this.dwbmName);
        //   this.$set(this.$refs.formComponent4.form, "createTime", showTime(new Date()));
        // }
        // if (this.Userorg.level === 1) {
        //   this.$set(this.$refs.formComponent4.form, "creator", this.UserInfo.userName);
        //   this.$set(this.$refs.formComponent4.form, "creatorUnit", this.dwbmName);
        //   this.$set(this.$refs.formComponent4.form, "createTime", showTime(new Date()));
        // } else if (this.Userorg.level === 2) {
        //   this.dispatchDialog.formConfig4.rules = {};
        //   this.$set(this.$refs.formComponent5.form, "creator", this.UserInfo.userName);
        //   this.$set(this.$refs.formComponent5.form, "creatorUnit", this.dwbmName);
        //   this.$set(this.$refs.formComponent5.form, "createTime", showTime(new Date()));
        // } else if (this.Userorg.level >= 3) {
        //   this.dispatchDialog.formConfig4.rules = {};
        //   this.dispatchDialog.formConfig5.rules = {};
        //   this.$set(this.$refs.formComponent6.form, "creator", this.UserInfo.userName);
        //   this.$set(this.$refs.formComponent6.form, "creatorUnit", this.dwbmName);
        //   this.$set(this.$refs.formComponent6.form, "createTime", showTime(new Date()));
        // }
      } else if (type === "apply" && !applyDetailVo.dispatchedApprovalUser) { // 审批
        this.$nextTick(() => {
          this.dispatchDialog.formConfig1.rules = {};
          this.dispatchDialog.formConfig4.rules = {};
          this.dispatchDialog.formConfig5.rules = {};
          this.dispatchDialog.formConfig6.rules = {};
          this.$set(this.$refs.formComponent7.form, "dispatchedApprovalUser", this.UserInfo.userName);
          this.$set(this.$refs.formComponent7.form, "dispatchedApprovalDept", this.dwbmName);
          this.$set(this.$refs.formComponent7.form, "dispatchedApprovalTime", showTime(new Date()));
        });
      }

      //  要根据orderType和当前状态  去判断显示表单，不用表单的禁用选项
      if (applyDetailVo.orderType === "dispatched") { // 新增的派遣单，新增的派遣单，新增的派遣单
        this.$refs.formComponent8.form = applyDetailVo;
        this.dispatchDialog.formConfig8.formData.forEach((item) => {
          if (item.prop === "acceptUnit") {
            getUnitAndNextUnit({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
        });
        //  根据部门匹配联系人
        GetByOrganization({ orgId: applyDetailVo.acceptUnitId }).then(res => {
          const option = res.map((item) => {
            return {
              label: item.realName,
              value: item.userId
            };
          });
          this.Usersoptions = res;
          this.dispatchDialog.formConfig8.formData[5].option = option; // 联系人
        });

        if (applyDetailVo.dispatchedStatus === 3) { // 新增派遣的待审批
          this.dispatchDialog.formConfig1.formData[0].isDisabled = true;
          this.dispatchDialog.formConfig8.rules = {};
          this.dispatchDialog.formConfig8.formData.forEach((item) => { item.isDisabled = true; });
          this.dispatchDialog.formConfig4.formData.forEach((item) => { item.isDisabled = true; });
          this.dispatchDialog.formConfig5.formData.forEach((item) => { item.isDisabled = true; });
          this.dispatchDialog.formConfig6.formData.forEach((item) => { item.isDisabled = true; });
        }
        // 根据派遣级别赋值到对应的form
        if (dispatchedDetailVoList.length === 1) { // 有派遣信息
          if (dispatchedDetailVoList[0].dispatchedLevel === 1) {
            this.$refs.formComponent4.form = dispatchedDetailVoList && dispatchedDetailVoList[0] || {};// 省
            //  根据部门匹配联系人
            getAccountOrgById({ ssbmId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
              const option = res.map((item) => {
                return {
                  label: item.realName,
                  value: item.id
                };
              });
              this.dispatchDialog.formConfig4.formData[2].option = option;
            });
            if (this.applyType === 1) {
              this.teamTableList = dispatchedDetailVoList[0].teamDetailVos;
              this.teamTableLength = dispatchedDetailVoList[0].dispatchedNum;
              this.$nextTick(() => {
                this.teamTableList.forEach((items, indexs) => {
                  const item = this.$refs[`formComponent4${indexs}`][0].form;
                  this.$set(item, "teamId", items.id);
                  this.$set(item, "teamName", items.teamName);
                  this.$set(item, "teamType", items.teamType);
                  this.$set(item, "teamMajor", items.teamMajor);
                });
              });
            } else if (this.applyType === 2) {
              this.dispatchDialog.formConfig4.table.tableData = dispatchedDetailVoList[0].vehicleDetailVos;
            } else if (this.applyType === 3) {
              this.dispatchDialog.formConfig4.table.tableData = dispatchedDetailVoList[0].equipDetailVos;
            } else if (this.applyType === 4) {
              this.dispatchDialog.formConfig4.table.tableData = dispatchedDetailVoList[0].suppliesDetailVos;
            }
            if (this.dispatchDialog.formConfig4.table.tableData.length > 0 || this.teamTableList.length > 0) {
              let bigIds = "";
              let ids = [];
              // 根据当前级别,分别获取对应table已经选中的数据
              if (this.applyType === 1) {
                bigIds = this.teamTableList[0].teamId; // 队伍ID
                this.teamTableList.forEach(el => {
                  el.memberSaveDtoList.forEach((i) => {
                    ids.push(i.id);
                  });
                });
              } else {
                bigIds = this.dispatchDialog.formConfig4.table.tableData[0].id; // 其他分类ID为id
                ids = this.dispatchDialog.formConfig4.table.tableData.map(i => { return i.id; });
              }
              this.$set(this.dispatchDialog.formConfig4.table.tableData, "smallIds", ids);
              this.$set(this.$refs.formComponent4.form, "bigIds", [bigIds]);
            }
          } else if (dispatchedDetailVoList[0].dispatchedLevel === 2) {
            this.$refs.formComponent5.form = dispatchedDetailVoList && dispatchedDetailVoList[0] || {};// 市
            //  根据部门匹配联系人
            getAccountOrgById({ ssbmId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
              const option = res.map((item) => {
                return {
                  label: item.realName,
                  value: item.id
                };
              });
              this.dispatchDialog.formConfig5.formData[2].option = option;
            });
            if (this.applyType === 1) {
              this.teamTableList = dispatchedDetailVoList[0].teamDetailVos;
              this.teamTableLength = dispatchedDetailVoList[0].dispatchedNum;
              this.$nextTick(() => {
                this.teamTableList.forEach((items, indexs) => {
                  const item = this.$refs[`formComponent5${indexs}`][0].form;
                  this.$set(item, "teamId", items.id);
                  this.$set(item, "teamName", items.teamName);
                  this.$set(item, "teamType", items.teamType);
                  this.$set(item, "teamMajor", items.teamMajor);
                });
              });
            } else if (this.applyType === 2) {
              this.dispatchDialog.formConfig5.table.tableData = dispatchedDetailVoList[0].vehicleDetailVos;
            } else if (this.applyType === 3) {
              this.dispatchDialog.formConfig5.table.tableData = dispatchedDetailVoList[0].equipDetailVos;
            } else if (this.applyType === 4) {
              this.dispatchDialog.formConfig5.table.tableData = dispatchedDetailVoList[0].suppliesDetailVos;
            }
            if (this.dispatchDialog.formConfig5.table.tableData.length > 0 || this.teamTableList.length > 0) {
              let bigIds = "";
              let ids = [];
              // 根据当前级别,分别获取对应table已经选中的数据
              if (this.applyType === 1) {
                bigIds = this.teamTableList[0].teamId; // 队伍ID
                this.teamTableList.forEach(el => {
                  el.memberSaveDtoList.forEach((i) => {
                    ids.push(i.id);
                  });
                });
              } else {
                bigIds = this.dispatchDialog.formConfig5.table.tableData[0].id; // 其他分类ID为id
                ids = this.dispatchDialog.formConfig5.table.tableData.map(i => { return i.id; });
              }
              this.$set(this.dispatchDialog.formConfig5.table.tableData, "smallIds", ids);
              this.$set(this.$refs.formComponent5.form, "bigIds", [bigIds]);
            }
          } else if (dispatchedDetailVoList[0].dispatchedLevel === 3) {
            this.$refs.formComponent6.form = dispatchedDetailVoList && dispatchedDetailVoList[0] || {};// 区
            //  根据部门匹配联系人
            getAccountOrgById({ ssbmId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
              const option = res.map((item) => {
                return {
                  label: item.realName,
                  value: item.id
                };
              });
              this.dispatchDialog.formConfig6.formData[2].option = option;
            });
            if (this.applyType === 1) {
              this.teamTableList = dispatchedDetailVoList[0].teamDetailVos;
              this.teamTableLength = dispatchedDetailVoList[0].dispatchedNum;
              this.$nextTick(() => {
                this.teamTableList.forEach((items, indexs) => {
                  const item = this.$refs[`formComponent6${indexs}`][0].form;
                  this.$set(item, "teamId", items.id);
                  this.$set(item, "teamName", items.teamName);
                  this.$set(item, "teamType", items.teamType);
                  this.$set(item, "teamMajor", items.teamMajor);
                });
              });
            } else if (this.applyType === 2) {
              this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[0].vehicleDetailVos;
            } else if (this.applyType === 3) {
              this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[0].equipDetailVos;
            } else if (this.applyType === 4) {
              this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[0].suppliesDetailVos;
            }
            if (this.dispatchDialog.formConfig6.table.tableData.length > 0 || this.teamTableList.length > 0) {
              let bigIds = "";
              let ids = [];
              // 根据当前级别,分别获取对应table已经选中的数据
              if (this.applyType === 1) {
                bigIds = this.teamTableList[0].teamId; // 队伍ID
                this.teamTableList.forEach(el => {
                  el.memberSaveDtoList.forEach((i) => {
                    ids.push(i.id);
                  });
                });
              } else {
                bigIds = this.dispatchDialog.formConfig6.table.tableData[0].id; // 其他分类ID为id
                ids = this.dispatchDialog.formConfig6.table.tableData.map(i => { return i.id; });
              }
              this.$set(this.dispatchDialog.formConfig6.table.tableData, "smallIds", ids);
              this.$set(this.$refs.formComponent6.form, "bigIds", [bigIds]);
            }

          }
        }

      } else if (applyDetailVo.orderType === "apply") { // 申请过来的的派遣单，申请过来的的派遣单，申请过来的的派遣单
        this.$refs.formComponent2.form = applyDetailVo;

        if (this.acceptLevel === 1) { // 省级
          if (this.applyLevel === 2 && this.isSend) { // 存在下发到地市
            this.dispatchDialog.formConfig4.formData.forEach((item) => { item.isDisabled = true; });
            // // 地市级派遣信息的责任单位和责任人默认显示为省公司选择的责任单位和责任人
            // this.$set(this.$refs.formComponent5.form, "dutyUnitId", dispatchedDetailVoList[0].dutyUnitId);
            // //  根据部门匹配联系人
            // GetByOrganization({ orgId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
            //   const option = res.map((item) => {
            //     return {
            //       label: item.realName,
            //       value: item.userId
            //     };
            //   });
            //   this.dispatchDialog.formConfig5.formData[1].option = option; // 联系人
            // });
            // this.$set(this.$refs.formComponent5.form, "dutyPersonId", dispatchedDetailVoList[0].dutyPersonId);
            this.dispatchDialog.titleConfig.splice(5, 1);
          } else { // 还没下发
            this.dispatchDialog.titleConfig.splice(4, 2);
          }
        } else if (this.acceptLevel === 2) { // 地市级
          if (this.applyLevel === 3 && this.isSend) { // 存在下发到区县
            this.dispatchDialog.formConfig5.formData.forEach((item) => { item.isDisabled = true; });
            // // 地市级派遣信息的责任单位和责任人默认显示为省公司选择的责任单位和责任人
            // this.$set(this.$refs.formComponent6.form, "dutyUnitId", dispatchedDetailVoList[0].dutyUnitId);
            // //  根据部门匹配联系人
            // GetByOrganization({ orgId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
            //   const option = res.map((item) => {
            //     return {
            //       label: item.realName,
            //       value: item.userId
            //     };
            //   });
            //   this.dispatchDialog.formConfig6.formData[1].option = option; // 联系人
            // });
            // this.$set(this.$refs.formComponent6.form, "dutyPersonId", dispatchedDetailVoList[0].dutyPersonId);
            this.dispatchDialog.titleConfig.splice(3, 1);
          } else { // 还没下发
            this.dispatchDialog.titleConfig.splice(3, 1);
            this.dispatchDialog.titleConfig.splice(4, 1);
            // if (type !== "apply") { // 不是审批的时候
            //   this.dispatchDialog.dialogConfig.btnList = [
            //     {
            //       name: "提交",
            //       type: "primary",
            //       id: "submit",
            //       size: "small"
            //     },
            //     {
            //       name: "保存",
            //       id: "submit",
            //       size: "small"
            //     },
            //     {
            //       name: "取消",
            //       id: "cancel",
            //       size: "small"
            //     }
            //   ];
            // }
          }
        }
        // else if (this.acceptLevel === 3) { // 区县级无下发（）
        //   this.dispatchDialog.formConfig6.formData.unshift(
        //     {
        //       type: "input",
        //       label: "资源派遣单",
        //       prop: "resourceDispatchedName",
        //       class: "sjgy"
        //     },
        //     {
        //       type: "selectTree",
        //       label: "责任单位及部门",
        //       prop: "dutyUnit",
        //       name: "dutyUnitId",
        //       title: "责任单位及部门选择",
        //       keyword: "dutyUnits6", // 搜索关键字，同一表单需要绑定唯一值
        //       treeRef: "dutyUnitRef6", // 树结构绑定的ref，同一表单需绑定唯一值
        //       commonClick: true, // 是否使用默认点击事件，
        //       clickClose: false, // 判断是否点击选择单位后是否立刻关闭弹窗，
        //       choose: false, // 判断是否可以多选
        //       ref: "dutyUnit_select6", // 同一表单需要绑定唯一ref，用于关闭对应弹窗
        //       class: "third",
        //       lableWidth: "151px",
        //       treeData: {
        //         data: [],
        //         default: ["1"],
        //         checked: [],
        //         props: {
        //           children: "children",
        //           label: "orgName",
        //           value: "id"
        //         }
        //       }
        //     },
        //     {
        //       type: "select",
        //       label: "责任人",
        //       prop: "dutyPersonId",
        //       name: "dutyPerson",
        //       class: "third",
        //       option: []
        //     });
        //   this.dispatchDialog.formConfig6.formData.forEach((item) => { // 获取区县级部门
        //     if (item.prop === "dutyUnit") {
        //       getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
        //         item.treeData.data = res;
        //       });
        //     }
        //   });
        //   this.dispatchDialog.titleConfig.splice(3, 2);
        // }

        // if (this.Userorg.level === 1) { // 省公司进来派遣或审批
        //   console.log("省公司进来派遣或审批");
        //   this.dispatchDialog.titleConfig.splice(4, 2);
        // } else if (this.Userorg.level === 2) {
        //   // 地市级派遣信息的责任单位和责任人默认显示为省公司选择的责任单位和责任人
        //   this.$set(this.$refs.formComponent5.form, "dutyUnitId", dispatchedDetailVoList[0].dutyUnitId);
        //   //  根据部门匹配联系人
        //   GetByOrganization({ orgId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
        //     const option = res.map((item) => {
        //       return {
        //         label: item.realName,
        //         value: item.userId
        //       };
        //     });
        //     this.dispatchDialog.formConfig5.formData[1].option = option; // 联系人
        //   });
        //   this.$set(this.$refs.formComponent5.form, "dutyPersonId", dispatchedDetailVoList[0].dutyPersonId);
        //   if (dispatchedDetailVoList.length === 0) { // 省公司还没下发时
        //     this.dispatchDialog.titleConfig.splice(4, 2);
        //   } else if (dispatchedDetailVoList.length >= 1) { // 省公司有数据下发了
        //     this.dispatchDialog.formConfig4.formData.forEach((item) => { item.isDisabled = true; });
        //     this.dispatchDialog.titleConfig.splice(5, 1);
        //   }
        // } else if (this.Userorg.level >= 3) { // 县公司进来，但是上面2级数据不一定
        //   this.dispatchDialog.formConfig4.formData.forEach((item) => { item.isDisabled = true; });
        //   this.dispatchDialog.formConfig5.formData.forEach((item) => { item.isDisabled = true; });
        // }

        // if (applyDetailVo.dispatchedStatus === 3) { // 申请派遣的待审批
        //   this.dispatchDialog.formConfig4.formData.forEach((item) => { item.isDisabled = true; });
        //   this.dispatchDialog.formConfig5.formData.forEach((item) => { item.isDisabled = true; });
        //   this.dispatchDialog.formConfig6.formData.forEach((item) => { item.isDisabled = true; });
        // }

        if (this.applyType === 1) { // 申请明细根据资源类型赋值
          this.dispatchDialog.formConfig3.table.tableData = applyDetailVo.applyResourceTeamDetail;
        } else if (this.applyType === 2) {
          this.dispatchDialog.formConfig3.table.tableData = applyDetailVo.applyResourceVehicleDetail;
        } else if (this.applyType === 3) {
          this.dispatchDialog.formConfig3.table.tableData = applyDetailVo.applyResourceEquipDetail;
        } else if (this.applyType === 4) {
          this.dispatchDialog.formConfig3.table.tableData = applyDetailVo.applyResourceSuppliesDetail;
        }

        if (dispatchedDetailVoList.length === 1) { // 同级申请获取信息 省，市，区县 3种情况
          if (this.acceptLevel === 1) { // 省级
            this.$refs.formComponent4.form = dispatchedDetailVoList && dispatchedDetailVoList[0] || {};
            //  根据部门匹配联系人
            getAccountOrgById({ ssbmId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
              const option = res.map((item) => {
                return {
                  label: item.realName,
                  value: item.id
                };
              });
              this.dispatchDialog.formConfig4.formData[2].option = option;
            });
            if (this.applyType === 1) {
              this.teamTableList = dispatchedDetailVoList[0].teamDetailVos;
              this.teamTableLength = dispatchedDetailVoList[0].dispatchedNum;
              this.$nextTick(() => {
                this.teamTableList.forEach((items, indexs) => {
                  const item = this.$refs[`formComponent4${indexs}`][0].form;
                  this.$set(item, "teamId", items.id);
                  this.$set(item, "teamName", items.teamName);
                  this.$set(item, "teamType", items.teamType);
                  this.$set(item, "teamMajor", items.teamMajor);
                });
              });
            } else if (this.applyType === 2) {
              this.dispatchDialog.formConfig4.table.tableData = dispatchedDetailVoList[0].vehicleDetailVos;
            } else if (this.applyType === 3) {
              this.dispatchDialog.formConfig4.table.tableData = dispatchedDetailVoList[0].equipDetailVos;
            } else if (this.applyType === 4) {
              this.dispatchDialog.formConfig4.table.tableData = dispatchedDetailVoList[0].suppliesDetailVos;
            }
            if (this.dispatchDialog.formConfig4.table.tableData.length > 0 || this.teamTableList.length > 0) {
              let bigIds = "";
              let ids = [];
              // 根据当前级别,分别获取对应table已经选中的数据
              if (this.applyType === 1) {
                bigIds = this.teamTableList[0].teamId; // 队伍ID
                this.teamTableList.forEach(el => {
                  el.memberSaveDtoList.forEach((i) => {
                    ids.push(i.id);
                  });
                });
              } else {
                bigIds = this.dispatchDialog.formConfig4.table.tableData[0].id; // 其他分类ID为id
                ids = this.dispatchDialog.formConfig4.table.tableData.map(i => { return i.id; });
              }
              this.$set(this.dispatchDialog.formConfig4.table.tableData, "smallIds", ids);
              this.$set(this.$refs.formComponent4.form, "bigIds", [bigIds]);
            }
          } else if (this.acceptLevel === 2) { // 地市级
            this.$refs.formComponent4.form = dispatchedDetailVoList && dispatchedDetailVoList[0] || {};
            //  根据部门匹配联系人
            getAccountOrgById({ ssbmId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
              const option = res.map((item) => {
                return {
                  label: item.realName,
                  value: item.id
                };
              });
              this.dispatchDialog.formConfig5.formData[2].option = option;
            });
            if (this.applyType === 1) {
              this.teamTableList = dispatchedDetailVoList[0].teamDetailVos;
              this.teamTableLength = dispatchedDetailVoList[0].dispatchedNum;
              this.$nextTick(() => {
                this.teamTableList.forEach((items, indexs) => {
                  const item = this.$refs[`formComponent5${indexs}`][0].form;
                  this.$set(item, "teamId", items.id);
                  this.$set(item, "teamName", items.teamName);
                  this.$set(item, "teamType", items.teamType);
                  this.$set(item, "teamMajor", items.teamMajor);
                });
              });
            } else if (this.applyType === 2) {
              this.dispatchDialog.formConfig5.table.tableData = dispatchedDetailVoList[0].vehicleDetailVos;
            } else if (this.applyType === 3) {
              this.dispatchDialog.formConfig5.table.tableData = dispatchedDetailVoList[0].equipDetailVos;
            } else if (this.applyType === 4) {
              this.dispatchDialog.formConfig5.table.tableData = dispatchedDetailVoList[0].suppliesDetailVos;
            }
            if (this.dispatchDialog.formConfig5.table.tableData.length > 0 || this.teamTableList.length > 0) {
              let bigIds = "";
              let ids = [];
              // 根据当前级别,分别获取对应table已经选中的数据
              if (this.applyType === 1) {
                bigIds = this.teamTableList[0].teamId; // 队伍ID
                this.teamTableList.forEach(el => {
                  el.memberSaveDtoList.forEach((i) => {
                    ids.push(i.id);
                  });
                });
              } else {
                bigIds = this.dispatchDialog.formConfig5.table.tableData[0].id; // 其他分类ID为id
                ids = this.dispatchDialog.formConfig5.table.tableData.map(i => { return i.id; });
              }
              this.$set(this.dispatchDialog.formConfig5.table.tableData, "smallIds", ids);
              this.$set(this.$refs.formComponent5.form, "bigIds", [bigIds]);
            }
          } else if (this.acceptLevel === 3) { // 区县级
            this.$refs.formComponent4.form = dispatchedDetailVoList && dispatchedDetailVoList[0] || {};
            //  根据部门匹配联系人
            getAccountOrgById({ ssbmId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
              const option = res.map((item) => {
                return {
                  label: item.realName,
                  value: item.id
                };
              });
              this.dispatchDialog.formConfig6.formData[2].option = option;
            });
            if (this.applyType === 1) {
              this.teamTableList = dispatchedDetailVoList[0].teamDetailVos;
              this.teamTableLength = dispatchedDetailVoList[0].dispatchedNum;
              this.$nextTick(() => {
                this.teamTableList.forEach((items, indexs) => {
                  const item = this.$refs[`formComponent6${indexs}`][0].form;
                  this.$set(item, "teamId", items.id);
                  this.$set(item, "teamName", items.teamName);
                  this.$set(item, "teamType", items.teamType);
                  this.$set(item, "teamMajor", items.teamMajor);
                });
              });
            } else if (this.applyType === 2) {
              this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[0].vehicleDetailVos;
            } else if (this.applyType === 3) {
              this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[0].equipDetailVos;
            } else if (this.applyType === 4) {
              this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[0].suppliesDetailVos;
            }
            if (this.dispatchDialog.formConfig6.table.tableData.length > 0 || this.teamTableList.length > 0) {
              let bigIds = "";
              let ids = [];
              // 根据当前级别,分别获取对应table已经选中的数据
              if (this.applyType === 1) {
                bigIds = this.teamTableList[0].teamId; // 队伍ID
                this.teamTableList.forEach(el => {
                  el.memberSaveDtoList.forEach((i) => {
                    ids.push(i.id);
                  });
                });
              } else {
                bigIds = this.dispatchDialog.formConfig6.table.tableData[0].id; // 其他分类ID为id
                ids = this.dispatchDialog.formConfig6.table.tableData.map(i => { return i.id; });
              }
              this.$set(this.dispatchDialog.formConfig6.table.tableData, "smallIds", ids);
              this.$set(this.$refs.formComponent6.form, "bigIds", [bigIds]);
            }
          }
        } else if (dispatchedDetailVoList.length === 2) { // 存在跨级申请获取信息 存在 省到地市， 地市到区县2种情况
          if (this.acceptLevel === 1) { // 省到地市
            this.$refs.formComponent4.form = dispatchedDetailVoList && dispatchedDetailVoList[0] || {}; // 上级
            this.$refs.formComponent5.form = dispatchedDetailVoList && dispatchedDetailVoList[1] || {}; // 下级
            //  根据部门匹配联系人
            getAccountOrgById({ ssbmId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
              const option = res.map((item) => {
                return {
                  label: item.realName,
                  value: item.id
                };
              });
              this.dispatchDialog.formConfig4.formData[2].option = option;
            });
            getAccountOrgById({ ssbmId: dispatchedDetailVoList[1].dutyUnitId }).then(res => {
              const option = res.map((item) => {
                return {
                  label: item.realName,
                  value: item.id
                };
              });
              this.dispatchDialog.formConfig5.formData[1].option = option;
            });
            if (this.applyType === 1) {
              this.teamTableList = dispatchedDetailVoList[1].teamDetailVos;
              this.teamTableLength = dispatchedDetailVoList[1].dispatchedNum;
              this.$nextTick(() => {
                this.teamTableList.forEach((items, indexs) => {
                  const item = this.$refs[`formComponent5${indexs}`][0].form;
                  this.$set(item, "teamId", items.id);
                  this.$set(item, "teamName", items.teamName);
                  this.$set(item, "teamType", items.teamType);
                  this.$set(item, "teamMajor", items.teamMajor);
                });
              });
            } else if (this.applyType === 2) {
              this.dispatchDialog.formConfig5.table.tableData = dispatchedDetailVoList[1].vehicleDetailVos;
            } else if (this.applyType === 3) {
              this.dispatchDialog.formConfig5.table.tableData = dispatchedDetailVoList[1].equipDetailVos;
            } else if (this.applyType === 4) {
              this.dispatchDialog.formConfig5.table.tableData = dispatchedDetailVoList[1].suppliesDetailVos;
            }
            if (this.dispatchDialog.formConfig5.table.tableData.length > 0 || this.teamTableList.length > 0) {
              let bigIds = "";
              let ids = [];
              // 根据当前级别,分别获取对应table已经选中的数据
              if (this.applyType === 1) {
                bigIds = this.teamTableList[0].teamId; // 队伍ID
                this.teamTableList.forEach(el => {
                  el.memberSaveDtoList.forEach((i) => {
                    ids.push(i.id);
                  });
                });
              } else {
                bigIds = this.dispatchDialog.formConfig5.table.tableData[0].id; // 其他分类ID为id
                ids = this.dispatchDialog.formConfig5.table.tableData.map(i => { return i.id; });
              }
              this.$set(this.dispatchDialog.formConfig5.table.tableData, "smallIds", ids);
              this.$set(this.$refs.formComponent5.form, "bigIds", [bigIds]);
            }
          } else if (this.acceptLevel === 2) { // 地市到区县
            this.$refs.formComponent4.form = dispatchedDetailVoList && dispatchedDetailVoList[0] || {}; // 上级
            this.$refs.formComponent5.form = dispatchedDetailVoList && dispatchedDetailVoList[1] || {}; // 下级

            if (this.applyType === 1) {
              this.teamTableList = dispatchedDetailVoList[1].teamDetailVos;
              this.teamTableLength = dispatchedDetailVoList[1].dispatchedNum;
              this.$nextTick(() => {
                this.teamTableList.forEach((items, indexs) => {
                  const item = this.$refs[`formComponent6${indexs}`][0].form;
                  this.$set(item, "teamId", items.id);
                  this.$set(item, "teamName", items.teamName);
                  this.$set(item, "teamType", items.teamType);
                  this.$set(item, "teamMajor", items.teamMajor);
                });
              });
            } else if (this.applyType === 2) {
              this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[1].vehicleDetailVos;
            } else if (this.applyType === 3) {
              this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[1].equipDetailVos;
            } else if (this.applyType === 4) {
              this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[1].suppliesDetailVos;
            }
            if (this.dispatchDialog.formConfig6.table.tableData.length > 0 || this.teamTableList.length > 0) {
              let bigIds = "";
              let ids = [];
              // 根据当前级别,分别获取对应table已经选中的数据
              if (this.applyType === 1) {
                bigIds = this.teamTableList[0].teamId; // 队伍ID
                this.teamTableList.forEach(el => {
                  el.memberSaveDtoList.forEach((i) => {
                    ids.push(i.id);
                  });
                });
              } else {
                bigIds = this.dispatchDialog.formConfig6.table.tableData[0].id; // 其他分类ID为id
                ids = this.dispatchDialog.formConfig6.table.tableData.map(i => { return i.id; });
              }
              this.$set(this.dispatchDialog.formConfig6.table.tableData, "smallIds", ids);
              this.$set(this.$refs.formComponent6.form, "bigIds", [bigIds]);
            }
          }
        }
        //   } else if (dispatchedDetailVoList.length === 3) { // 存在区县级的时候获取信息
        //     this.$refs.formComponent4.form = dispatchedDetailVoList && dispatchedDetailVoList[0] || {};// 省
        //     this.$refs.formComponent5.form = dispatchedDetailVoList && dispatchedDetailVoList[1] || {};// 市
        //     this.$refs.formComponent6.form = dispatchedDetailVoList && dispatchedDetailVoList[2] || {};// 区
        //     //  根据部门匹配联系人
        //     GetByOrganization({ orgId: dispatchedDetailVoList[0].dutyUnitId }).then(res => {
        //       const option = res.map((item) => {
        //         return {
        //           label: item.realName,
        //           value: item.userId
        //         };
        //       });
        //       this.dispatchDialog.formConfig4.formData[2].option = option;
        //     });
        //     GetByOrganization({ orgId: dispatchedDetailVoList[1].dutyUnitId }).then(res => {
        //       const option = res.map((item) => {
        //         return {
        //           label: item.realName,
        //           value: item.userId
        //         };
        //       });
        //       this.dispatchDialog.formConfig5.formData[1].option = option;
        //     });
        //     GetByOrganization({ orgId: dispatchedDetailVoList[2].dutyUnitId }).then(res => {
        //       const option = res.map((item) => {
        //         return {
        //           label: item.realName,
        //           value: item.userId
        //         };
        //       });
        //       this.dispatchDialog.formConfig6.formData[1].option = option;
        //     });
        //     if (this.applyType === 1) {
        //       this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[2].memberDetailVos;
        //     } else if (this.applyType === 2) {
        //       this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[2].vehicleDetailVos;
        //     } else if (this.applyType === 3) {
        //       this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[2].equipDetailVos;
        //     } else if (this.applyType === 4) {
        //       this.dispatchDialog.formConfig6.table.tableData = dispatchedDetailVoList[2].suppliesDetailVos;
        //     }
        //     // 根据当前级别,分别获取对应table已经选中的数据
        //     let bigIds = "";
        //     // 根据当前级别,分别获取对应table已经选中的数据
        //     if (this.applyType === 1) {
        //       bigIds = this.dispatchDialog.formConfig4.table.tableData[0].teamId; // 队伍ID;其他分类ID为id
        //     } else {
        //       bigIds = this.dispatchDialog.formConfig4.table.tableData[0].id; // 队伍ID;其他分类ID为id
        //     }
        //     const ids = this.dispatchDialog.formConfig6.table.tableData.map(i => { return i.id; });
        //     this.$set(this.dispatchDialog.formConfig6.table.tableData, "smallIds", ids);
        //     this.$set(this.$refs.formComponent6.form, "bigIds", [bigIds]);
        //   }
      }

      if (type !== "apply") { // 编辑和派遣获取详情如果有数据就改变按钮状态
        if (this.dispatchDialog.formConfig4.table.tableData.length > 0 ||
          this.dispatchDialog.formConfig5.table.tableData.length > 0 ||
          this.dispatchDialog.formConfig6.table.tableData.length > 0 || this.teamTableList.length > 0) {
          this.dispatchDialog.dialogConfig.btnList = [
            {
              name: "提交",
              type: "primary",
              id: "submit",
              size: "small"
            },
            {
              name: "保存",
              id: "submit",
              size: "small"
            },
            {
              name: "取消",
              id: "cancel",
              size: "small"
            }
          ];
        }
      }
    },
    // 新增
    dialogVisible() {
      this.addOredit = 0;
      this.dispatchedStatus = 999;
      this.dispatchDialog.titleConfig.splice(1, 2, TeamFormDialog.taskTitleSlot);
      if (this.Userorg.level === 1) {
        this.dispatchDialog.titleConfig.splice(3, 2);
        this.dispatchDialog.formConfig4.formData.forEach((item) => { // 获取地市级部门
          if (item.prop === "dutyUnit") {
            getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
        });
      } else if (this.Userorg.level === 2) {
        this.dispatchDialog.titleConfig.splice(2, 1);
        this.dispatchDialog.titleConfig.splice(3, 1);
        this.dispatchDialog.formConfig5.formData.forEach((item) => { // 获取区县级部门
          if (item.prop === "dutyUnit") {
            getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
        });
      } else {
        this.dispatchDialog.titleConfig.splice(2, 2);
        this.dispatchDialog.formConfig6.formData.unshift(
          {
            type: "input",
            label: "资源派遣单",
            prop: "resourceDispatchedName",
            class: "sjgy"
          },
          {
            type: "selectTree",
            label: "责任单位及部门",
            prop: "dutyUnit",
            name: "dutyUnitId",
            title: "责任单位及部门选择",
            keyword: "dutyUnits6", // 搜索关键字，同一表单需要绑定唯一值
            treeRef: "dutyUnitRef6", // 树结构绑定的ref，同一表单需绑定唯一值
            commonClick: true, // 是否使用默认点击事件，
            clickClose: false, // 判断是否点击选择单位后是否立刻关闭弹窗，
            choose: false, // 判断是否可以多选
            ref: "dutyUnit_select6", // 同一表单需要绑定唯一ref，用于关闭对应弹窗
            class: "third",
            lableWidth: "151px",
            treeData: {
              data: [],
              default: ["1"],
              checked: [],
              props: {
                children: "children",
                label: "orgName",
                value: "id"
              }
            }
          },
          {
            type: "select",
            label: "责任人",
            prop: "dutyPersonId",
            name: "dutyPerson",
            class: "third",
            option: []
          });
        this.dispatchDialog.formConfig6.formData.forEach((item) => { // 获取区县级部门
          if (item.prop === "dutyUnit") {
            getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
        });
      }
      this.dispatchDialog.formConfig1.formData[0].isDisabled = false;
      this.getGetResponse(); // 渲染命令单
      this.dispatchDialog.formConfig8.formData.forEach((item) => {
        if (item.prop === "acceptUnit") {
          getUnitAndNextUnit({ orgId: this.Userorg.orgId }).then(res => {
            item.treeData.data = res;
          });
        }
      });
      this.dispatchDialog.dialogConfig.btnList = [
        {
          name: "提交",
          type: "primary",
          id: "submit",
          size: "small"
        },
        {
          name: "保存",
          id: "submit",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ];
      this.dispatchDialog.dialogConfig.isShow = true;
      this.$nextTick(() => {
        if (this.Userorg.level === 1) {
          this.$set(this.$refs.formComponent4.form, "creator", this.UserInfo.userName);
          this.$set(this.$refs.formComponent4.form, "creatorUnit", this.dwbmName);
          this.$set(this.$refs.formComponent4.form, "createTime", showTime(new Date()));
        } else if (this.Userorg.level === 2) {
          this.$set(this.$refs.formComponent5.form, "creator", this.UserInfo.userName);
          this.$set(this.$refs.formComponent5.form, "creatorUnit", this.dwbmName);
          this.$set(this.$refs.formComponent5.form, "createTime", showTime(new Date()));
        } else if (this.Userorg.level >= 3) {
          this.$set(this.$refs.formComponent6.form, "creator", this.UserInfo.userName);
          this.$set(this.$refs.formComponent6.form, "creatorUnit", this.dwbmName);
          this.$set(this.$refs.formComponent6.form, "createTime", showTime(new Date()));
        }
      });

    },
    // 编辑获取详情，改变按钮
    async handleEdit(id) {
      this.addOredit = 1;
      this.dispatchId = id;
      this.dispatchDialog.titleConfig.splice(1, 2, TeamFormDialog.taskTitleSlot);
      if (this.Userorg.level === 1) {
        this.dispatchDialog.titleConfig.splice(3, 2);
        this.dispatchDialog.formConfig4.formData.forEach((item) => { // 获取地市级部门
          if (item.prop === "dutyUnit") {
            getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
        });
      } else if (this.Userorg.level === 2) {
        this.dispatchDialog.titleConfig.splice(2, 1);
        this.dispatchDialog.titleConfig.splice(3, 1);
        // this.dispatchDialog.formConfig5.formData.unshift({
        //   type: "input",
        //   label: "资源派遣单",
        //   prop: "resourceDispatchedName",
        //   class: "sjgy"
        // });
        this.dispatchDialog.formConfig5.formData.forEach((item) => { // 获取区县级部门
          if (item.prop === "dutyUnit") {
            getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
        });
      } else {
        this.dispatchDialog.titleConfig.splice(2, 2);
        this.dispatchDialog.formConfig6.formData.unshift(
          {
            type: "input",
            label: "资源派遣单",
            prop: "resourceDispatchedName",
            class: "sjgy"
          },
          {
            type: "selectTree",
            label: "责任单位及部门",
            prop: "dutyUnit",
            name: "dutyUnitId",
            title: "责任单位及部门选择",
            keyword: "dutyUnits6", // 搜索关键字，同一表单需要绑定唯一值
            treeRef: "dutyUnitRef6", // 树结构绑定的ref，同一表单需绑定唯一值
            commonClick: true, // 是否使用默认点击事件，
            clickClose: false, // 判断是否点击选择单位后是否立刻关闭弹窗，
            choose: false, // 判断是否可以多选
            ref: "dutyUnit_select6", // 同一表单需要绑定唯一ref，用于关闭对应弹窗
            class: "third",
            lableWidth: "151px",
            treeData: {
              data: [],
              default: ["1"],
              checked: [],
              props: {
                children: "children",
                label: "orgName",
                value: "id"
              }
            }
          },
          {
            type: "select",
            label: "责任人",
            prop: "dutyPersonId",
            name: "dutyPerson",
            class: "third",
            option: []
          }
        );
        this.dispatchDialog.formConfig6.formData.forEach((item) => { // 获取区县级部门
          if (item.prop === "dutyUnit") {
            getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
        });
      }
      this.dispatchDialog.formConfig1.formData[0].isDisabled = false;
      this.GetDispacthDetails(id, "Edit");
      this.getGetResponse(); // 渲染命令单
      this.dispatchDialog.formConfig8.formData.forEach((item) => {
        if (item.prop === "acceptUnit") {
          getUnitAndNextUnit({ orgId: this.Userorg.orgId }).then(res => {
            item.treeData.data = res;
          });
        }
      });
      this.dispatchDialog.dialogConfig.btnList = [
        {
          name: "提交",
          type: "primary",
          id: "submit",
          size: "small"
        },
        {
          name: "保存",
          id: "submit",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ];
    },
    // 派遣获取详情，改变按钮
    async dispatch(id) {
      this.addOredit = 1;
      this.dispatchId = id;
      this.GetDispacthDetails(id, "dispatch");
      this.getGetResponse(); // 渲染命令单
      this.dispatchDialog.formConfig7.formData[0].isDisabled = true;
      this.dispatchDialog.formConfig4.formData.forEach((item) => { // 获取本级单位及下一级的单位部门
        if (item.prop === "dutyUnit") {
          getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
            item.treeData.data = res;
          });
        }
      });
      this.dispatchDialog.formConfig5.formData.forEach((item) => { // 获取本级单位及下一级的单位部门
        if (item.prop === "dutyUnit") {
          getDepartmentNext({ orgId: this.Userorg.orgId }).then(res => {
            item.treeData.data = res;
          });
        }
      });

    },
    // 审批时获取详情，改变按钮
    async apply(id, orderType) {
      this.btnShow = false; // 隐藏台账、仓库3个按钮
      this.dispatchId = id;
      this.dispatchDialog.titleConfig.push(this.dispatchDialog.applyTitle);
      if (orderType === "dispatched") {
        this.dispatchDialog.titleConfig.splice(1, 2, this.dispatchDialog.taskTitleSlot);
        if (this.Userorg.level === 1) {
          this.dispatchDialog.titleConfig.splice(3, 2);
        } else if (this.Userorg.level === 2) {
          this.dispatchDialog.titleConfig.splice(2, 1);
          this.dispatchDialog.titleConfig.splice(3, 1);
        } else {
          this.dispatchDialog.titleConfig.splice(2, 2);
        }
      }
      this.getGetResponse(); // 渲染命令单
      this.GetDispacthDetails(id, "apply", orderType);
      this.dispatchDialog.dialogConfig.btnList = [
        {
          name: "同意",
          type: "primary",
          id: "Approve",
          approveSign: "pass",
          size: "small"
        },
        {
          name: "驳回",
          id: "Approve",
          approveSign: "reject",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ];
    },
    // 审批
    async Approve(item) {
      let approveSign = "";
      if (item.approveSign === "pass") {
        approveSign = "pass";
      } else {
        approveSign = "reject";
      }
      const parmas = {
        approvalOpinion: this.$refs.formComponent7.form.dispatchedApprovalOpinion || "",
        approveSign: approveSign,
        id: this.dispatchId
      };
      if (item.approveSign === "pass") {
        this.gzlAudit(3, parmas);
      } else {
        this.gzlAudit(4, parmas);
      }
      this.cancel();
      this.GetDispacthLists();
    },
    // 删除
    async deleted(id) {
      this.$confirm("确定删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        DispacthDeleted({ id }).then(res => {
          if (res) {
            this.$message({
              message: "删除成功",
              type: "success"
            });
            this.GetDispacthLists();
          }
        });
      });
    },
    handleSelectTree(arg, item) {
      if (item.id === "dutyUnit") {
        this.$set(this.form, "dutyUnitId", arg[0].id);
        this.$set(this.form, "dutyUnit", arg[0].orgName);
      }
    },
    // 列表查询
    async onSubmit(val) {
      console.log(val);
      const parmas = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        applyType: this.applyType || "", // 资源类型
        sourceInfo: val.sourceInfo || "", // 响应命令单
        resourceDispatchedName: val.resourceDispatchedName, // 资源派遣单
        dutyUnitId: val.dutyUnitId, // 受理单位及部门
        dutyPersonId: val.dutyPersonId, // 责任人
        dispatchedStartTime: val.dispatchedTime ? val.dispatchedTime[0] : "", // 开始时间
        dispatchedEndTime: val.dispatchedTime ? val.dispatchedTime[1] : "", // 结束时间\
        dispatchedStatus: val.dispatchedStatus || "" // 状态
      };
      const res = await GetDispacthList(parmas);
      this.table.tableData = res.data;
      this.table.paginationAtrrs.total = res.total;
    },
    // 列表重置条件
    resetForm() {
      this.form = this.$options.data().form;
      this.GetDispacthLists();
    },
    // 列表设置页码
    handleSizeChange(val, form) {
      this.pageNum = val["current-page"];
      this.pageSize = val["page-size"];
      this.onSubmit(form);
    },
    // 队伍资源
    async GetTeamResources(num, size, unitId, unit, teamName, teamMajor, teamTypeName) {
      const orgId = this.Userorg.level === 1 ? "" : this.Userorg.orgId;
      // const orgName = this.Userorg.level === 1 ? "" : this.Userorg.orgName;
      const res = await GetTeamResource({
        pageNum: num || this.ChooseTableConfig.paginationAtrrs["current-page"],
        pageSize: size || this.ChooseTableConfig.paginationAtrrs["page-size"],
        unitId: unitId || orgId || "", // 所属单位
        // unit: unit || orgName || "", // 所属单位名称
        teamName: teamName || "",
        teamMajor: teamMajor || "",
        teamTypeName: teamTypeName || ""
      });
      this.ChooseTableConfig.tableData = res.data;
      this.ChooseTableConfig.paginationAtrrs.total = res.total;
      // 根据当前级别,分别获取对应table已经选中的数据
      var formComponentIndex = "";
      if (this.Userorg.level === 1) {
        formComponentIndex = "formComponent4";
      } else if (this.Userorg.level === 2) {
        formComponentIndex = "formComponent5";
      } else if (this.Userorg.level >= 3) {
        formComponentIndex = "formComponent6";
      }
      const result = this.$refs[formComponentIndex].form.bigIds || [this.$refs[formComponentIndex].form.id] || [];
      if (result.length > 0) {
        this.$nextTick(() => {
          this.$refs?.ChooseConfig?.$refs?.teamTabel.toggleSelection(result);
        });
      }
    },
    // 队员
    async GetTeamMemberResources(num, size, id, name, memberType, memberMajor, memberAbility) {
      var formComponentIndex = "";
      if (this.Userorg.level === 1) {
        formComponentIndex = "formComponent4";
      } else if (this.Userorg.level === 2) {
        formComponentIndex = "formComponent5";
      } else if (this.Userorg.level >= 3) {
        formComponentIndex = "formComponent6";
      }
      const res = await GetTeamMemberResource({
        pageNum: num || this.ChooseTableConfig.paginationAtrrs["current-page"],
        pageSize: size || this.ChooseTableConfig.paginationAtrrs["page-size"],
        teamId: id || this.$refs[formComponentIndex].form.bigIds[0] || "",
        name: name || "",
        memberType: memberType || "",
        memberMajor: memberMajor || "",
        memberAbility: memberAbility || ""
      });
      this.ChooseTableConfig.tableData = res.data;
      this.ChooseTableConfig.paginationAtrrs.total = res.total;

      // var formConfigIndex = ""; // 根据当前级别,分别获取对应table已经选中的数据
      // if (this.Userorg.level === 1) {
      //   formConfigIndex = "formConfig4";
      // } else if (this.Userorg.level === 2) {
      //   formConfigIndex = "formConfig5";
      // } else if (this.Userorg.level >= 3) {
      //   formConfigIndex = "formConfig6";
      // }
      const result = [];
      this.teamTableList.forEach(el => {
        el.memberSaveDtoList.forEach((i) => {
          result.push(i.id);
        });
      });
      if (result.length > 0) {
        this.$nextTick(() => {
          this.$refs?.ChooseConfig?.$refs?.playerTabel.toggleSelection(result);
        });
      }
    },
    // 仓库
    async GetResourceWarehouses(num, size, type, unitId, warehouseId, largeCategory, middleCategory, smallCategory) {
      const orgId = this.Userorg.level === 1 ? "" : this.Userorg.orgId;
      const res = await GetResourceWarehouse({
        pageNum: num || this.ChooseTableConfig.paginationAtrrs["current-page"],
        pageSize: size || this.ChooseTableConfig.paginationAtrrs["page-size"],
        type: type || "", // 仓库类型
        unitId: unitId || orgId || "", // 所属单位
        largeCategory: largeCategory || "", // 大类 对应 车辆性质
        middleCategory: middleCategory || "", // 中类 对应 车辆用途
        smallCategory: smallCategory || "", // 小类 对应 车辆类型
        warehouseId: warehouseId || "" // 仓库名称


      });
      this.ChooseTableConfig.tableData = res.data;
      this.ChooseTableConfig.paginationAtrrs.total = res.total;
      // 根据当前级别,分别获取对应table已经选中的数据
      var formComponentIndex = "";
      if (this.Userorg.level === 1) {
        formComponentIndex = "formComponent4";
      } else if (this.Userorg.level === 2) {
        formComponentIndex = "formComponent5";
      } else if (this.Userorg.level >= 3) {
        formComponentIndex = "formComponent6";
      }
      const result = this.$refs[formComponentIndex].form.bigIds || [this.$refs[formComponentIndex].form.id] || [];
      if (result.length > 0) {
        this.$nextTick(() => {
          this.$refs?.ChooseConfig?.$refs[type].toggleSelection(result);
        });
      }
    },
    // 车辆
    async GetVehicleResources(num, size, unitId, vehicleProperties, vehicleUsage, vehicleType) {
      const orgId = this.Userorg.level === 1 ? "" : this.Userorg.orgId;
      const res = await GetVehicleResource({
        pageNum: num || this.ChooseTableConfig.paginationAtrrs["current-page"],
        pageSize: size || this.ChooseTableConfig.paginationAtrrs["page-size"],
        unitId: unitId || orgId || "", // 所属单位
        vehicleProperties: vehicleProperties || "",
        vehicleUsage: vehicleUsage || "",
        vehicleType: vehicleType || ""

      });
      this.ChooseTableConfig.tableData = res.data;
      this.ChooseTableConfig.paginationAtrrs.total = res.total;

      var formConfigIndex = ""; // 根据当前级别,分别获取对应table已经选中的数据
      if (this.Userorg.level === 1) {
        formConfigIndex = "formConfig4";
      } else if (this.Userorg.level === 2) {
        formConfigIndex = "formConfig5";
      } else if (this.Userorg.level >= 3) {
        formConfigIndex = "formConfig6";
      }
      const result = this.dispatchDialog[formConfigIndex].table.tableData.smallIds || [];
      if (result.length > 0) {
        this.$nextTick(() => {
          this.$refs?.ChooseConfig?.$refs?.vehicleTabel.toggleSelection(result);
        });
      }
    },
    // 装备
    async GetEquipResources(num, size, unitId, largeCategory, middleCategory, smallCategory) {
      const orgId = this.Userorg.level === 1 ? "" : this.Userorg.orgId;
      const res = await GetEquipResource({
        pageNum: num || this.ChooseTableConfig.paginationAtrrs["current-page"],
        pageSize: size || this.ChooseTableConfig.paginationAtrrs["page-size"],
        unitId: unitId || orgId || "", // 所属单位
        largeCategory: largeCategory || "",
        middleCategory: middleCategory || "",
        smallCategory: smallCategory || ""

      });
      console.log(res.data, "装备");
      this.ChooseTableConfig.tableData = res.data;
      this.ChooseTableConfig.paginationAtrrs.total = res.total;

      var formConfigIndex = ""; // 根据当前级别,分别获取对应table已经选中的数据
      if (this.Userorg.level === 1) {
        formConfigIndex = "formConfig4";
      } else if (this.Userorg.level === 2) {
        formConfigIndex = "formConfig5";
      } else if (this.Userorg.level >= 3) {
        formConfigIndex = "formConfig6";
      }
      const result = this.dispatchDialog[formConfigIndex].table.tableData.smallIds || [];
      if (result.length > 0) {
        this.$nextTick(() => {
          this.$refs?.ChooseConfig?.$refs?.EquipmentDetailTabel.toggleSelection(result);
        });
      }
    },
    // 物资
    async GetSuppliesResources(num, size, unitId, largeCategory, middleCategory, smallCategory) {
      const orgId = this.Userorg.level === 1 ? "" : this.Userorg.orgId;
      const res = await GetSuppliesResource({
        pageNum: num || this.ChooseTableConfig.paginationAtrrs["current-page"],
        pageSize: size || this.ChooseTableConfig.paginationAtrrs["page-size"],
        unitId: unitId || orgId || "", // 所属单位
        largeCategory: largeCategory || "",
        middleCategory: middleCategory || "",
        smallCategory: smallCategory || ""

      });
      console.log(res.datam, "物资");
      this.ChooseTableConfig.tableData = res.data;
      this.ChooseTableConfig.paginationAtrrs.total = res.total;

      var formConfigIndex = ""; // 根据当前级别,分别获取对应table已经选中的数据
      if (this.Userorg.level === 1) {
        formConfigIndex = "formConfig4";
      } else if (this.Userorg.level === 2) {
        formConfigIndex = "formConfig5";
      } else if (this.Userorg.level >= 3) {
        formConfigIndex = "formConfig6";
      }
      const result = this.dispatchDialog[formConfigIndex].table.tableData.smallIds || [];
      if (result.length > 0) {
        this.$nextTick(() => {
          this.$refs?.ChooseConfig?.$refs?.MaterialDetailTable.toggleSelection(result);
        });
      }
    },
    // 资源选择设置页码
    // dialogHandleSizeChange(select, item, val) {
    //   console.log(val, "页码页码页码页码");
    //   const title = this.ChooseConfig.title;
    //   if (title === "队伍选择" || title === "队伍台账") {
    //     this.GetTeamResources(val["current-page"], val["page-size"]);
    //   } else if (title === "队员选择") {
    //     this.GetTeamMemberResources(val["current-page"], val["page-size"], this.resourceFathersId);
    //   } else if (title === "车辆台账") {
    //     this.GetResourceWarehouses(val["current-page"], val["page-size"], "vehicle");
    //   } else if (title === "车辆选择") {
    //     this.GetVehicleResources(val["current-page"], val["page-size"]);
    //   } else if (title === "装备台账" || title === "装备仓库") {
    //     this.GetResourceWarehouses(val["current-page"], val["page-size"], "equ");
    //   } else if (title === "装备选择") {
    //     this.GetEquipResources(val["current-page"], val["page-size"], this.resourceFathersId);
    //   } else if (title === "物资台账" || title === "物资仓库") {
    //     this.GetResourceWarehouses(val["current-page"], val["page-size"], "supplies");
    //   } else if (title === "物资选择") {
    //     this.GetSuppliesResources(val["current-page"], val["page-size"], this.resourceFathersId);
    //   }
    // },
    // 点击资源大类，小类
    async getResourcesData(data) {
      // item 区分物资类别, index为1 是仓库，为2是小类明细
      const index = data.index;
      const item = data.code;
      const config = `${item}Config${index}`; // 获取对应资源分类模板
      this.ChooseConfig = this[config].ChooseConfig;
      this.ChooseFormConfig = this[config].ChooseFormConfig;
      this.ChooseTableConfig = this[config].ChooseTableConfig;
      this.ChooseConfig.title = data.name;
      this.ChooseConfig.isShow = true;
      if (data.codeType) {
        this.ChooseTableConfig["isSelectFlag"] = false;
        this.ChooseConfig.btnList = [];
      } else {
        this.ChooseConfig.btnList = [
          {
            name: "确认",
            type: "primary",
            id: "confirm",
            size: "small"
          },
          {
            name: "取消",
            id: "cancel",
            size: "small"
          }
        ];
        this.ChooseTableConfig["isSelectFlag"] = true;
      }
      var formConfigIndex = ""; // 根据当前级别,分别获取对应table已经选中的数据
      if (this.Userorg.level === 1) {
        formConfigIndex = "formConfig4";
      } else if (this.Userorg.level === 2) {
        formConfigIndex = "formConfig5";
      } else if (this.Userorg.level >= 3) {
        formConfigIndex = "formConfig6";
      }
      if (item === "TeamData") { // 队伍
        // 队伍查询条件下拉
        this.ChooseFormConfig.formData.forEach((item) => {
          if (item.dic) {
            getBatchDicList({ codes: [`${item.dic}`] }).then((res) => {
              const option = res[`${item.dic}`].map((val) => {
                return {
                  label: val.dicName,
                  value: val.dicName
                };
              });
              item.option = option;
            });
          }
          if (item.name === "unitId") {
            getUnitAndNextUnit({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
        });
        if (index === 1) { // 队伍、台账
          this.GetTeamResources();
        } else {
          if (this.teamTableList.length > 0) {
            this.GetTeamMemberResources(1, 10, this.teamTableList[0].teamId);
          } else {
            const result = this.dispatchDialog[formConfigIndex].table.tableData.smallIds || [];
            if (result.length > 0) {
              this.$nextTick(() => {
                this.$refs?.ChooseConfig?.$refs?.playerTabel.toggleSelection(result);
              });
            }
          }
        }
      } else if (item === "CarData") { // 车辆
        // 车辆查询条件下拉
        this.ChooseFormConfig.formData.forEach((item) => {
          if (item.dic) {
            getBatchDicList({ codes: [`${item.dic}`] }).then((res) => {
              const option = res[`${item.dic}`].map((val) => {
                return {
                  label: val.dicName,
                  value: val.dicName
                };
              });
              item.option = option;
            });
          }
          if (item.name === "unitId") {
            getUnitAndNextUnit({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
        });
        if (index === 1) { // 车辆台账
          this.GetResourceWarehouses("", "", "vehicle");
        } else {
          const result = this.dispatchDialog[formConfigIndex].table.tableData.smallIds || [];
          if (result.length > 0) {
            this.$nextTick(() => {
              this.$refs?.ChooseConfig?.$refs?.vehicleTabel.toggleSelection(result);
            });
          }
          this.GetVehicleResources();
        }
      } else if (item === "EquipmentData") { // 装备
        this.ChooseFormConfig.formData.forEach((item) => {
          if (item.dic) {
            getBatchDicList({ codes: [`${item.dic}`] }).then((res) => {
              const option = res[`${item.dic}`].map((val) => {
                return {
                  label: val.dicName,
                  value: val.dicName
                };
              });
              item.option = option;
            });
          }
          if (item.name === "unitId") {
            getUnitAndNextUnit({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
          if (item.prop === "warehouseId") {
            getWarehouseName().then(res => {
              const option = res.map((val) => {
                return {
                  label: val.name,
                  value: val.code
                };
              });
              item.option = option;
            });
          }
        });
        if (index === 1 || index === 0) { // 装备台账0,仓库1
          this.GetResourceWarehouses("", "", "equ");
        } else {
          const result = this.dispatchDialog[formConfigIndex].table.tableData.smallIds || [];
          if (result.length > 0) {
            this.$nextTick(() => {
              this.$refs?.ChooseConfig?.$refs?.EquipmentDetailTabel.toggleSelection(result);
            });
          }
          this.GetEquipResources();
        }
      } else if (item === "MaterialData") { // 物资
        // 物资查询条件下拉
        this.ChooseFormConfig.formData.forEach((item) => {
          if (item.dic) {
            getBatchDicList({ codes: [`${item.dic}`] }).then((res) => {
              const option = res[`${item.dic}`].map((val) => {
                return {
                  label: val.dicName,
                  value: val.dicName
                };
              });
              item.option = option;
            });
          }
          if (item.name === "unitId") {
            getUnitAndNextUnit({ orgId: this.Userorg.orgId }).then(res => {
              item.treeData.data = res;
            });
          }
          if (item.prop === "warehouseId") {
            getWarehouseName().then(res => {
              const option = res.map((val) => {
                return {
                  label: val.name,
                  value: val.code
                };
              });
              item.option = option;
            });
          }
        });
        if (index === 1 || index === 0) { // 物资台账0,仓库1
          this.GetResourceWarehouses("", "", "supplies");
        } else {
          const result = this.dispatchDialog[formConfigIndex].table.tableData.smallIds || [];
          if (result.length > 0) {
            this.$nextTick(() => {
              this.$refs?.ChooseConfig?.$refs?.MaterialDetailTable.toggleSelection(result);
            });
          }
          this.GetSuppliesResources();
        }
      }

    },
    // 选择资源
    async teamAdd(item, selecetion) {
      const {title} = item;
      if (title === "队伍选择") {
        if (selecetion.length > 1) {
          this.$message.error("只能选择一只队伍！");
          return;
        }
        if (selecetion.length === 0) {
          this.$message.error("请至少选择一只队伍！");
          return;
        }
        if (this.Userorg.level === 1) {
          const { id, teamName, teamTypeName, teamMajor } = selecetion[0];
          this.teamIndex = this.teamTableList.findIndex((el) => el.teamId === id); // 判断是否存在选择的队伍
          if (this.teamIndex === -1) {
            this.teamTableList.push({
              teamId: id,
              teamName,
              teamType: teamTypeName,
              teamMajor,
              memberSaveDtoList: []
            });
            const index = this.teamTableList.length - 1;
            this.$nextTick(() => {
              const item = this.$refs[`formComponent4${index}`][0].form;
              this.$set(item, "teamId", selecetion[0].id);
              this.$set(item, "teamName", selecetion[0].teamName);
              this.$set(item, "teamType", selecetion[0].teamTypeName);
              this.$set(item, "teamMajor", selecetion[0].teamMajor);
            });
            this.teamIndex = index; // 当前操作的队伍是第几条
          }
        } else if (this.Userorg.level === 2) {
          const { id, teamName, teamTypeName, teamMajor } = selecetion[0];
          this.teamIndex = this.teamTableList.findIndex((el) => el.teamId === id); // 判断是否存在选择的队伍
          if (this.teamIndex === -1) {
            this.teamTableList.push({
              teamId: id,
              teamName,
              teamType: teamTypeName,
              teamMajor,
              memberSaveDtoList: []
            });
            const index = this.teamTableList.length - 1;
            this.$nextTick(() => {
              const item = this.$refs[`formComponent5${index}`][0].form;
              this.$set(item, "teamId", selecetion[0].id);
              this.$set(item, "teamName", selecetion[0].teamName);
              this.$set(item, "teamType", selecetion[0].teamTypeName);
              this.$set(item, "teamMajor", selecetion[0].teamMajor);
            });
            this.teamIndex = index; // 当前操作的队伍是第几条
          }
        } else if (this.Userorg.level >= 3) {
          const { id, teamName, teamTypeName, teamMajor } = selecetion[0];
          this.teamIndex = this.teamTableList.findIndex((el) => el.teamId === id); // 判断是否存在选择的队伍
          if (this.teamIndex === -1) {
            this.teamTableList.push({
              teamId: id,
              teamName,
              teamType: teamTypeName,
              teamMajor,
              memberSaveDtoList: []
            });
            const index = this.teamTableList.length - 1;
            this.$nextTick(() => {
              const item = this.$refs[`formComponent6${index}`][0].form;
              this.$set(item, "teamId", selecetion[0].id);
              this.$set(item, "teamName", selecetion[0].teamName);
              this.$set(item, "teamType", selecetion[0].teamTypeName);
              this.$set(item, "teamMajor", selecetion[0].teamMajor);
            });
            this.teamIndex = index; // 当前操作的队伍是第几条
          }
        }
        this.ChooseConfig = this.TeamDataConfig2.ChooseConfig;
        this.ChooseFormConfig = this.TeamDataConfig2.ChooseFormConfig;
        this.ChooseTableConfig = this.TeamDataConfig2.ChooseTableConfig;
        this.GetTeamMemberResources(1, 10, selecetion[0].id);
        this.resourceFathersId = selecetion[0].id; // 记录队伍ID
        this.ChooseConfig.isShow = true;
        // 队员查询条件下拉
        this.ChooseFormConfig.formData.forEach((item) => {
          if (item.dic) {
            getBatchDicList({ codes: [`${item.dic}`] }).then((res) => {
              const option = res[`${item.dic}`].map((val) => {
                return {
                  label: val.dicName,
                  value: val.dicName
                };
              });
              item.option = option;
            });
          }
        });
      } else if (title === "队员选择") {
        // if (this.Userorg.level === 1) {
        //   if (!this.$refs.formComponent4.form.teamName) {
        //     this.$message.error("请先选择队伍！");
        //     return;
        //   }
        // } else if (this.Userorg.level === 2) {
        //   if (!this.$refs.formComponent5.form.teamName) {
        //     this.$message.error("请先选择队伍！");
        //     return;
        //   }
        // } else if (this.Userorg.level >= 3) {
        //   if (!this.$refs.formComponent6.form.teamName) {
        //     this.$message.error("请先选择队伍！");
        //     return;
        //   }
        // }
        if (selecetion.length === 0) {
          this.$message.error("请至少选择一个队员！");
          return;
        }

        this.ChooseConfig.isShow = false;
        // } else if (title === "车辆台账") {
        //   if (selecetion.length > 1) {
        //     this.$message.error("只能选择一个单位！")
        //     return
        //   }
        //   if (selecetion.length === 0) {
        //     this.$message.error("请至少选择一个单位！")
        //     return
        //   }
        //   this.ChooseConfig = this.CarDataConfig2.ChooseConfig
        //   this.ChooseFormConfig = this.CarDataConfig2.ChooseFormConfig
        //   this.ChooseTableConfig = this.CarDataConfig2.ChooseTableConfig
        //   this.GetVehicleResources(1, 10, selecetion[0].unitId)
        //   this.ChooseConfig.isShow = true
      } else if (title === "车辆选择") {
        if (selecetion.length === 0) {
          this.$message.error("请至少选择一台车辆！");
          return;
        }
        //  车辆数量就是数据条数dispatchedNum
        if (this.Userorg.level === 1) {
          this.$set(this.$refs.formComponent4.form, "dispatchedNum", selecetion.length);
        } else if (this.Userorg.level === 2) {
          this.$set(this.$refs.formComponent5.form, "dispatchedNum", selecetion.length);
        } else if (this.Userorg.level >= 3) {
          this.$set(this.$refs.formComponent6.form, "dispatchedNum", selecetion.length);
        }
        this.ChooseConfig.isShow = false;
      } else if (title === "装备仓库") {
        if (selecetion.length > 1) {
          this.$message.error("只能选择一个装备仓库！");
          return;
        }
        if (selecetion.length === 0) {
          this.$message.error("请至少选择一个装备仓库！");
          return;
        }
        if (this.Userorg.level === 1) {
          this.$set(this.$refs.formComponent4.form, "warehouseName", selecetion[0].warehouseName);
          this.$set(this.$refs.formComponent4.form, "warehouseContact", selecetion[0].contact);
          this.$set(this.$refs.formComponent4.form, "warehouseContactWay", selecetion[0].contactWay);
        } else if (this.Userorg.level === 2) {
          this.$set(this.$refs.formComponent5.form, "warehouseName", selecetion[0].warehouseName);
          this.$set(this.$refs.formComponent5.form, "warehouseContact", selecetion[0].contact);
          this.$set(this.$refs.formComponent5.form, "warehouseContactWay", selecetion[0].contactWay);
        } else if (this.Userorg.level >= 3) {
          this.$set(this.$refs.formComponent6.form, "warehouseName", selecetion[0].warehouseName);
          this.$set(this.$refs.formComponent6.form, "warehouseContact", selecetion[0].contact);
          this.$set(this.$refs.formComponent6.form, "warehouseContactWay", selecetion[0].contactWay);
        }
        this.ChooseConfig = this.EquipmentDataConfig2.ChooseConfig;
        this.ChooseFormConfig = this.EquipmentDataConfig2.ChooseFormConfig;
        this.ChooseTableConfig = this.EquipmentDataConfig2.ChooseTableConfig;
        this.GetEquipResources(1, 10, selecetion[0].unitId);
        this.resourceFathersId = selecetion[0].unitId; // 记录仓库ID
        this.ChooseConfig.isShow = true;
        // 装备查询条件下拉
        this.ChooseFormConfig.formData.forEach((item) => {
          if (item.dic) {
            getBatchDicList({ codes: [`${item.dic}`] }).then((res) => {
              const option = res[`${item.dic}`].map((val) => {
                return {
                  label: val.dicName,
                  value: val.dicName
                };
              });
              item.option = option;
            });
          }
        });
      } else if (title === "装备选择") {
        if (selecetion.length === 0) {
          this.$message.error("请至少选择一种装备！");
          return;
        }
        let dispatchedNums = 0;
        dispatchedNums = selecetion.reduce((prev, cur) => prev + cur.requireCount, 0);
        // 这里的 dispatchedNum  是 table中requireCount数量之和
        if (this.Userorg.level === 1) {
          this.$set(this.$refs.formComponent4.form, "dispatchedNum", dispatchedNums);
        } else if (this.Userorg.level === 2) {
          this.$set(this.$refs.formComponent5.form, "dispatchedNum", dispatchedNums);
        } else if (this.Userorg.level >= 3) {
          this.$set(this.$refs.formComponent6.form, "dispatchedNum", dispatchedNums);
        }
        this.ChooseConfig.isShow = false;
      } else if (title === "物资仓库") {
        if (selecetion.length > 1) {
          this.$message.error("只能选择一个物资仓库！");
          return;
        }
        if (selecetion.length === 0) {
          this.$message.error("请至少选择一个物资仓库！");
          return;
        }
        if (this.Userorg.level === 1) {
          this.$set(this.$refs.formComponent4.form, "warehouseName", selecetion[0].warehouseName);
          this.$set(this.$refs.formComponent4.form, "warehouseContact", selecetion[0].contact);
          this.$set(this.$refs.formComponent4.form, "warehouseContactWay", selecetion[0].contactWay);
        } else if (this.Userorg.level === 2) {
          this.$set(this.$refs.formComponent5.form, "warehouseName", selecetion[0].warehouseName);
          this.$set(this.$refs.formComponent5.form, "warehouseContact", selecetion[0].contact);
          this.$set(this.$refs.formComponent5.form, "warehouseContactWay", selecetion[0].contactWay);
        } else if (this.Userorg.level >= 3) {
          this.$set(this.$refs.formComponent6.form, "warehouseName", selecetion[0].warehouseName);
          this.$set(this.$refs.formComponent6.form, "warehouseContact", selecetion[0].contact);
          this.$set(this.$refs.formComponent6.form, "warehouseContactWay", selecetion[0].contactWay);
        }
        this.ChooseConfig = this.MaterialDataConfig2.ChooseConfig;
        this.ChooseFormConfig = this.MaterialDataConfig2.ChooseFormConfig;
        this.ChooseTableConfig = this.MaterialDataConfig2.ChooseTableConfig;
        this.GetSuppliesResources(1, 10, selecetion[0].unitId);
        this.resourceFathersId = selecetion[0].unitId; // 记录仓库ID
        this.ChooseConfig.isShow = true;
        // 物资查询条件下拉
        this.ChooseFormConfig.formData.forEach((item) => {
          if (item.dic) {
            getBatchDicList({ codes: [`${item.dic}`] }).then((res) => {
              const option = res[`${item.dic}`].map((val) => {
                return {
                  label: val.dicName,
                  value: val.dicName
                };
              });
              item.option = option;
            });
          }
        });
      } else if (title === "物资选择") {
        if (selecetion.length === 0) {
          this.$message.error("请至少选择一种物资！");
          return;
        }
        let dispatchedNums = 0;
        dispatchedNums = selecetion.reduce((prev, cur) => prev + cur.requireCount, 0);
        // 这里的 dispatchedNum  是 table中requireCount数量之和
        if (this.Userorg.level === 1) {
          this.$set(this.$refs.formComponent4.form, "dispatchedNum", dispatchedNums);
        } else if (this.Userorg.level === 2) {
          this.$set(this.$refs.formComponent5.form, "dispatchedNum", dispatchedNums);
        } else if (this.Userorg.level >= 3) {
          this.$set(this.$refs.formComponent6.form, "dispatchedNum", dispatchedNums);
        }
        this.ChooseConfig.isShow = false;
      }
      const ids = selecetion.map(i => { return i.id; });
      // 选择完成带入数据
      if (this.Userorg.level === 1) {
        if (item.type === "detailData") {
          if (this.applyType === 1) {
            this.teamTableList[this.teamIndex].memberSaveDtoList = selecetion;
          } else {
            this.dispatchDialog.formConfig4.table.tableData = selecetion;
          }
          this.$set(this.dispatchDialog.formConfig4.table.tableData, "smallIds", ids);
        } else {
          this.$set(this.$refs.formComponent4.form, "bigIds", ids);
        }
      } else if (this.Userorg.level === 2) {
        if (item.type === "detailData") {
          if (this.applyType === 1) {
            this.teamTableList[this.teamIndex].memberSaveDtoList = selecetion;
          } else {
            this.dispatchDialog.formConfig5.table.tableData = selecetion;
          }
          this.$set(this.dispatchDialog.formConfig5.table.tableData, "smallIds", ids);
        } else {
          this.$set(this.$refs.formComponent5.form, "bigIds", ids);
        }
      } else if (this.Userorg.level >= 3) {
        if (item.type === "detailData") {
          if (this.applyType === 1) {
            this.teamTableList[this.teamIndex].memberSaveDtoList = selecetion;
          } else {
            this.dispatchDialog.formConfig6.table.tableData = selecetion;
          }
          this.$set(this.dispatchDialog.formConfig6.table.tableData, "smallIds", ids);
        } else {
          this.$set(this.$refs.formComponent6.form, "bigIds", ids);
        }
      }

      if (title === "队员选择") {
        let teamTableLength = 0;
        teamTableLength = this.teamTableList.reduce((prev, cur) => prev + cur.memberSaveDtoList.length, 0);
        if (this.Userorg.level === 1) {
          this.$set(this.$refs.formComponent4.form, "dispatchedNum", teamTableLength);
        } else if (this.Userorg.level === 2) {
          this.$set(this.$refs.formComponent5.form, "dispatchedNum", teamTableLength);
        } else if (this.Userorg.level >= 3) {
          this.$set(this.$refs.formComponent6.form, "dispatchedNum", teamTableLength);
        }
      }
      this.dispatchDialog.dialogConfig.btnList = [
        {
          name: "提交",
          type: "primary",
          id: "submit",
          size: "small"
        },
        {
          name: "保存",
          id: "submit",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ];
    },
    // 物资选择查询
    // largeCategory
    // 车辆性质/装备大类
    // middleCategory
    // 车辆用途/装备中类
    // smallCategory
    // 车辆类型/装备小类
    // 仓库类型 vehicle-车辆，equ-装备物资，supplies-物资
    dialogQuery() {
      const formData = this.$refs.ChooseConfig.$refs.formComponent.form;
      const { "current-page": pageNum, "page-size": pageSize } = this.$refs.ChooseConfig.$refs[this.ChooseTableConfig.compRef].paginationAtrrsInner;
      const item = this.ChooseConfig;
      const title = item.title;
      if (title === "队伍选择" || title === "队伍台账") {
        const { unitId, unit, teamName, teamMajor, teamTypeName } = formData;
        this.GetTeamResources(pageNum, pageSize, unitId, unit, teamName, teamMajor, teamTypeName);
      } else if (title === "队员选择") {
        const { name, memberType, memberMajor, memberAbility } = formData;
        this.GetTeamMemberResources(pageNum, pageSize, this.resourceFathersId || "", name, memberType, memberMajor, memberAbility);
      } else if (title === "车辆台账") {
        const { unitId, largeCategory, middleCategory, smallCategory } = formData;
        this.GetResourceWarehouses(pageNum, pageSize, "vehicle", unitId, "", largeCategory, middleCategory, smallCategory);
      } else if (title === "车辆选择") {
        const { unitId, vehicleProperties, vehicleUsage, vehicleType } = formData;
        this.GetVehicleResources(pageNum, pageSize, unitId, vehicleProperties, vehicleUsage, vehicleType);
      } else if (title === "装备台账") {
        const { largeCategory, middleCategory, smallCategory } = formData;
        this.GetResourceWarehouses(pageNum, pageSize, "equ", "", "", largeCategory, middleCategory, smallCategory);
      } else if (title === "装备仓库") {
        const { unitId, warehouseId } = formData;
        this.GetResourceWarehouses(pageNum, pageSize, "equ", unitId, warehouseId);
      } else if (title === "装备选择") {
        const { largeCategory, middleCategory, smallCategory } = formData;
        this.GetEquipResources(pageNum, pageSize, this.resourceFathersId || "", largeCategory, middleCategory, smallCategory);
      } else if (title === "物资台账") {
        const { largeCategory, middleCategory, smallCategory } = formData;
        this.GetResourceWarehouses(pageNum, pageSize, "supplies", "", "", largeCategory, middleCategory, smallCategory);
      } else if (title === "物资仓库") {
        const { unitId, warehouseId } = formData;
        this.GetResourceWarehouses(pageNum, pageSize, "supplies", unitId, warehouseId);
      } else if (title === "物资选择") {
        const { largeCategory, middleCategory, smallCategory } = formData;
        this.GetSuppliesResources(pageNum, pageSize, this.resourceFathersId || "", largeCategory, middleCategory, smallCategory);
      }
    },

    // 物资选择重置
    dialogReset() {
      this.$refs.ChooseConfig.$refs.formComponent.form = this.$refs.ChooseConfig.$refs.formComponent.$options.data().form;
      this.dialogQuery();
    },
    // 物资选择关闭弹窗
    chooseClose(val) {
      this.ChooseConfig.isShow = false;
    },
    goSourceInfo(id) {
      // 命令单详情
      this.$router.push({
        name: "EmergencyResponseinfo",
        query: { id }
      });
    },
    detailList(id, orderType) {
      // 跳转详情
      this.$router.push({
        name: "ResourceDispatchDetail",
        query: { id, type: this.applyType, orderType }
      });
    }
  }
};
</script>

<style scoped lang="less">@import "../../../../assets/style/pop-upNotification.less";
@import "../../../../assets/style/ComponentStyle.less";
@import "../../../../assets/style/common.less";

.EmergencyList {
  height: 97%;
}

:deep(.el-breadcrumb__inner.is-link) {
  font-weight: 100;
  color: #fff;
}

.EmergencyList :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
  color: #3270ff;
}

.box {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 15px;
  background-color: #fff;
  border-radius: 4px;
  padding: 10px;
  box-sizing: border-box;
}

:deep(.el-table--striped .el-table__body tr.el-table__row--striped.el-table__row--striped.el-table__row--striped td) {
  background-color: #f8f9f8;
  /*隔行变色*/
}

//鼠标悬浮样式
:deep(tr.hover-row) {

  &,
  &.el-table__row--striped {

    &,
    &.current-row {
      >td.el-table__cell {
        background: none;
      }
    }
  }
}

.tableDiv {
  :deep(.leftTopBtn) {
    height: 0;
    margin-bottom: 0;
  }
}</style>
